. Net (C #) platform call: the default string sending form is unmanagedtype. lptstr, ......

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.