Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

Proposal to extend documentation about interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Allberg - 19 Oct 2004 22:44 GMT
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.

Thanks,

John Allberg
Robert Jordan - 19 Oct 2004 23:19 GMT
> Hi!
>
[quoted text clipped - 18 lines]
> 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
John Allberg - 21 Oct 2004 13:02 GMT
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

>> Hi!
>>
[quoted text clipped - 32 lines]
> bye
> Rob
"Peter Huang" - 22 Oct 2004 03:33 GMT
Hi John,

You may try to take a look at the link to see if that is what you want.
Default Marshaling for Strings
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpcondefaultmarshalingforstrings.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

"Peter Huang" - 26 Oct 2004 09:33 GMT
Hi,

If you have any more concerns on it, please feel free to post here.

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.