Interoperability-use the C/C ++ type of unmanaged function base

Source: Internet
Author: User

1. Use the methods provided by Microsoft's C Runtime Library msvcrt. dll and the functions provided by Win32 API to call the platform.
CodeAs follows:

 
Class program {// Microsoft's C Runtime Library msvcrt. the puts method provided by DLL [dllimport ("msvcrt. DLL ")] Static extern int puts (string MSG); [dllimport (" msvcrt. DLL ")] Static extern int _ flushall (); // function provided by Win32 API for platform calling [dllimport (" user32.dll ", entrypoint =" MessageBox ")] public static extern int MessageBox (INT hwnd, string lptext, string lpcaption, int wtype); static void main (string [] ARGs) {puts ("Hello world test! "); _ Flushall (); MessageBox (0," Hello world test! "," Title is here ", 0 );}}

2. Use of tools. To view the function information contained in the DLL, you can use the following tools: depends.exe?dumpbin.exe, PE explorer, etc.

The dumpbin format is as follows:

 

3. Use the entrypoint field to rename the function.

[Dllimport ("nativelib. dll", entrypoint = "printmsg")] public static extern void printmsgrename (string MSG );

Printmsg must be the same as the non-hosted function name. printmsgrename is the renamed function name.

 

 

 

 

 

 

 

 

 

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.