Arno Garrels wrote:
> My sample above as two Unicode code points:
>
> UStr := #$FF5E#$FF5E;
>
> Try to convert this string with WideCharToMultiByte() to ansi code
> page 50220, the result is two question marks "??". Both MLang's
> ConvertINetUnicodeToMultybyte() and iconv give the correct result.
If someone wants to give it a trial, here's the MLang header .pas:
{code}
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Arno Garrels <[email protected]>
Description: A few header translations from MS mlang.h.
Windows system API like MultiByteToWideChar or CharNext are
buggy or do not support some commonly used Ansi charsets.
Especially when it comes to stream encoding on-the-fly
the mlang API provides more options than the system API.
Requires Internet Explorer 5 or better, all functions fail
with HRESULT E_NOTIMPL if the library isn't loaded.
Creation: March 19, 2010
Version: 1.00
EMail: http://www.overbyte.be [email protected]
Support: Use the mailing list [email protected]
Follow "support" link at http://www.overbyte.be for subscription.
Legal issues: Copyright (C) Microsoft Corporation. All Rights Reserved.
Translator Arno Garrels <[email protected]>
History:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit OverbyteIcsMLang;
// Requires Internet Explorer 5 or better //
{$WEAKPACKAGEUNIT}
interface
uses
Windows;
function ConvertInetString(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnSrcSize: PInteger;
lpDstStr: PBYTE;
lpnDstSize: PInteger
): HRESULT;
function ConvertInetMultibyteToUnicode(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnMultiCharCount: PInteger;
lpDstStr: LPWSTR;
lpnWideCharCount: PInteger
): HRESULT;
function ConvertInetUnicodeToMultibyte(
lpdwMode: LPDWORD;
dwEncoding: DWORD;
lpSrcStr: LPCWSTR;
lpnWideCharCount: PInteger;
lpDstStr: LPSTR;
lpnMultiCharCount: PInteger
): HRESULT;
function IsConvertInetStringAvailable(
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD
): HRESULT;
function Load_MLang: Boolean;
implementation
type
TConvertInetString = function(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnSrcSize: PInteger;
lpDstStr: PBYTE;
lpnDstSize: PInteger
): HRESULT; stdcall;
TConvertInetMultibyteToUnicode = function(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnMultiCharCount: PInteger;
lpDstStr: LPWSTR;
lpnWideCharCount: PInteger
): HRESULT; stdcall;
TConvertInetUnicodeToMultibyte = function(
lpdwMode: LPDWORD;
dwEncoding: DWORD;
lpSrcStr: LPCWSTR;
lpnWideCharCount: PInteger;
lpDstStr: LPSTR;
lpnMultiCharCount: PInteger
): HRESULT; stdcall;
TIsConvertInetStringAvailable = function(
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD
): HRESULT; stdcall;
var
fptrConvertInetString : TConvertInetString = nil;
fptrConvertInetMultibyteToUnicode : TConvertInetMultibyteToUnicode = nil;
fptrConvertInetUnicodeToMultibyte : TConvertInetUnicodeToMultibyte = nil;
fptrIsConvertInetStringAvailable : TIsConvertInetStringAvailable = nil;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function Load_MLang: Boolean;
var
h : HMODULE;
begin
if Assigned(fptrConvertINetString) then
Result := TRUE
else begin
h := LoadLibrary('mlang.dll');
if h = 0 then
Result := FALSE
else begin
fptrConvertINetString := GetProcAddress(h, 'ConvertINetString');
fptrConvertINetMultiByteToUnicode := GetProcAddress(h,
'ConvertINetMultiByteToUnicode');
fptrConvertINetUnicodeToMultiByte := GetProcAddress(h,
'ConvertINetUnicodeToMultiByte');
fptrIsConvertINetStringAvailable := GetProcAddress(h,
'IsConvertINetStringAvailable');
Result := TRUE;
end;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ S_OK Performed the conversion successfully. }
{ S_FALSE The specified conversion is not supported on the system. }
{ E_FAIL An error has occurred. }
function ConvertInetString(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnSrcSize: PInteger;
lpDstStr: PBYTE;
lpnDstSize: PInteger
): HRESULT;
begin
if Assigned(fptrConvertINetString) or Load_MLang then
Result := fptrConvertINetString(lpdwMode, dwSrcEncoding, dwDstEncoding,
lpSrcStr, lpnSrcSize, lpDstStr, lpnDstSize)
else
Result := E_NOTIMPL;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ S_OK Performed the conversion successfully. }
{ S_FALSE The specified conversion is not supported on the system. }
{ E_FAIL An error has occurred. }
function ConvertInetMultibyteToUnicode(
lpdwMode: LPDWORD;
dwSrcEncoding: DWORD;
lpSrcStr: LPCSTR;
lpnMultiCharCount: PInteger;
lpDstStr: LPWSTR;
lpnWideCharCount: PInteger
): HRESULT;
begin
if Assigned(fptrConvertINetString) or Load_MLang then
Result := fptrConvertInetMultibyteToUnicode(lpdwMode, dwSrcEncoding,
lpSrcStr, lpnMultiCharCount, lpDstStr, lpnWideCharCount)
else
Result := E_NOTIMPL;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ S_OK Performed the conversion successfully. }
{ S_FALSE The specified conversion is not supported on the system. }
{ E_FAIL An error has occurred. }
function ConvertInetUnicodeToMultibyte(
lpdwMode: LPDWORD;
dwEncoding: DWORD;
lpSrcStr: LPCWSTR;
lpnWideCharCount: PInteger;
lpDstStr: LPSTR;
lpnMultiCharCount: PInteger
): HRESULT;
begin
if Assigned(fptrConvertINetString) or Load_MLang then
Result := fptrConvertInetUnicodeToMultibyte(lpdwMode, dwEncoding,
lpSrcStr, lpnWideCharCount, lpDstStr, lpnMultiCharCount)
else
Result := E_NOTIMPL;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ S_OK The function can perform the conversion. }
{ S_FALSE The conversion is not supported on the system. }
{ E_INVALIDARG One or more arguments are invalid. }
function IsConvertInetStringAvailable(
dwSrcEncoding: DWORD;
dwDstEncoding: DWORD
): HRESULT;
begin
if Assigned(fptrConvertINetString) or Load_MLang then
Result := fptrIsConvertInetStringAvailable(dwSrcEncoding, dwDstEncoding)
else
Result := E_NOTIMPL;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
end.
{code}
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be