MsdnArticleNot clear: http://msdn.microsoft.com/en-us/library/s9ts558h.aspx
The default sending form of the com call of the string described in this article is unmanagedtype. BSTR, and the default sending form of the platform call is unmanagedtype. lptstr. This lptstr is platform-related, that is, the tchar definition in winapi (98/me is ANSI, NT/2000/XP /... Is Unicode ). Then this paragraph is over ...... Yes, all of the above mentioned in msdn are correct, but it should mention the character set selection called by the platform, that is, about dllimportattribute. charset field, because the string sending form called by the above platform is and dllimportattribute. charset is related. Charset is ANSI (the default value is this), and the string will be enclosed by ANSI encoding. If it is charset. Unicode, the string will be enclosed by Unicode encoding. If it is charset. Auto, the string will be sent in the "default form of platform call: unmanagedtype. lptstr" mentioned above! (That's why charset. Auto always appears in many platforms calling the dllimport feature ).
Let's look at this example:
[Dllimport("User32.dll")]
Static Extern IntMessageboxa (IntptrHwnd,StringText,StringCaption,UintType );
Here, the messageboxa function of the API is referenced (note that there is a "a" next to it, which represents the ANSI encoded function). If the Platform calls the string to mail, it is always unmanagedtype by default. in the case of lptstr, in my Windows 7, this method will certainly not successfully display the specified string, because this is a function that only supports ANSI. In fact, it can be displayed, because the charset field value of dllimportattribute is charset. ANSI by default!
We recommend that you read another article:
. Net (C #): The Platform calls dllimportattribute. charset and string sending encoding.