API invocation of the Gospel--p/invoke API declaration automatically generated

Source: Internet
Author: User
Tags win32

See a lot of online users on the Internet. NET program to invoke the Win32 API, or call their own VC DLL provided in the function, always be generated by the correct C function in C # in the correct declaration and bothered, and generate C + + structure in C # declaration-days, there is nothing more disgusting than this thing. Because:

1. If your structure contains TCHAR string members, you need to consider the case of ANSI and Unicode DLLs.

2. If your structure contains an array member, you need to consider a fixed-length array, rather than the corresponding C # data type.

3. If your structure contains a federation (union), you need to use the EXPLICT option if the consortium contains the structure.

4. You also need to consider that your structure can be run on both 32-and 64-bit machines at the same time.

5. You also have to consider the padding optimization of the C compiler for the structure.

6. You also have to consider the. NET to optimize the structure, for example, the CLR transforms the order of some. NET struct members to make more efficient use of memory.

7. If your structure contains other structures.

8. If your structure contains a function pointer ...

9. If your structure contains an array of function pointers.

10. If your structure contains a pointer ...

11. If there are some members of your structure that are set by the called C function.

The CLR provides layout options for several structures, what auto, what explicit, what sequential

13. Some of the structure of the situation is described above the synthesis of the situation, think of our variant structure it.

If the structure is defined incorrectly, in use, the CLR simply throws a accessviolationexception, which is called every day, not the Earth.

Another scenario is to define the declaration of the. NET structure in C so that C or C + + programs can use this structure to invoke. NET's class library, this transformation is also a painful process.

It seems that Microsoft itself is deeply affected. NET lame p/invoke support poison, so reluctantly released the P/invoke Interop Assistant tool, you can go to the following link to download this tool:

Http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe

In fact, this tool has been open source, you can from here

http://www.codeplex.com/clrinterop/

Download to its source code.

A brief introduction to its usage
automatically generate Native function or struct declaration in. NET program , switch to "Sigimp Translate Snippet" label, and then copy Native function or struct declaration to "Native Code snippet" text box, and then select the "Auto Generate" dialog box, click on "Generate" to get the corresponding. NET Declaration

find the declaration in. NET in the Win32 API , select "Sigimp Search", and enter the function or structure name you want to find in the "Name" text box.

validation or generation. NET function (or struct) in C , switch to "sigexp" and open a. NET assembly containing P/invoke function calls, which displays the corresponding C declaration and tells you where the C # declaration was written incorrectly.

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.