Re: Proposal to extend documentation about interop
From: John Allberg (smudasmuda_at_nospam.nospam)
Date: 10/21/04
- Next message: Benoit Courchesne: "Why does my PrinterSettings.GetHdevmode() returns garbage ???"
- Previous message: Rodrigue: "safearray"
- In reply to: Robert Jordan: "Re: Proposal to extend documentation about interop"
- Next in thread: Peter Huang: "Re: Proposal to extend documentation about interop"
- Reply: Peter Huang: "Re: Proposal to extend documentation about interop"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 21 Oct 2004 14:02:57 +0200
You're right, I'm probably using one of those, whatever is the default for
"string". Since this is within a structure within an array I can't use a
simple array of bytes (like what the conversion to UTF-8 returns), I have to
use "String".
Frankly, I have no idea what default conversion is used for "string", but it
is received in C as char*.
I don't care if Win32 has support for UTF-8, I have already done the
conversion in .Net and the dll I'm calling has native support for UTF-8.
That's not the issue.
My point is that when reading about p/invoke in MSDN, there is no
information about that there is a character conversion. The only thing about
character set is the DllImportAttribute.CharSet, but that is more about what
entrypoint to use.
I still think that the documentation should be updated to clearly state that
there is a character set conversion during automatic p/invoke from Unicode
to whatever the Windows station is using.
Regards,
John Allberg
"Robert Jordan" <robertj@gmx.net> wrote in message
news:cl43uh$5u4$03$1@news.t-online.com...
> John Allberg wrote:
>
>> Hi!
>>
>> I think the MSDN docs about interop doesn't state clearly enough that
>> there is a character encoding conversion automaticly done from Unicode to
>> the characterset for the computer during interop.
>>
>> This got me really puzzled for a few days.
>>
>> I've got a legacy C-application (dll) that takes in UTF-8 encoded strings
>> in an array of structs. I call that C-dll from C# which works fine, as
>> long as I use ansi characters, for example english. When sending in
>> swedish characters (where the utf-8 encoding becomes two bytes) such as
>> åäö the lowercase works fine, but the uppercase ÅÄÖ simply comes out as
>> invalid utf-8 encoding of the character FF.
>>
>> I solved it by doing the conversion of UTF-8 to bytes and when going back
>> to string used the encoder for "Default" and converting those bytes to a
>> "unicode-string". That way, when the interop converts the string from
>> Unicode to "Default", the UTF-8 once again surfaces.
>>
>> So my suggestion is to update the MSDN doc to state this conversion
>> clearly enough.
>
> The automatic p/invoke conversion can be applied only to those
> legacy types:
>
> - LPSTR (ansi encoding, 1 byte)
> - LPWSTR (unicode encoding. 2 bytes)
> - LPTSTR (platform specific, one of the above)
> - BSTR
>
> You cannot properly import UTF-8 because Win32 doesn't support
> UTF-8 for the legacy API either.
>
> bye
> Rob
- Next message: Benoit Courchesne: "Why does my PrinterSettings.GetHdevmode() returns garbage ???"
- Previous message: Rodrigue: "safearray"
- In reply to: Robert Jordan: "Re: Proposal to extend documentation about interop"
- Next in thread: Peter Huang: "Re: Proposal to extend documentation about interop"
- Reply: Peter Huang: "Re: Proposal to extend documentation about interop"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|