C # platform call procedure

Source: Internet
Author: User

1、 clrinsideout2008_01.exe Program

2. Merge the declarations of all C functions, structures, and constants into one file.

3. Remove all pre-compiled commands and header file import declarations.

4. Remove macros defined as functions

5. Use the above program to convert it, check the first error carefully, and correct it.

6. Copy it to the C # class library and sort it out.

7. Specify the dll name for Function Import.

8. Add call conventions for Functions

9. Add a call convention for the delegate

Form: [UnmagedFunctionPointer (CallingConvention. Cdecl)]

10. search with the keyword "Error" to solve the problem.

11. Platform calls are function-centric and can be deleted from useless structures, delegates, constants, and enumerations.

12. Repeat it carefully to find unreasonable places.

13. char * is changed to StringBuilder rather than IntPtr;

Change BOOL to bool instead of int, and add [return: financialas (UnmanagedType. Bool)];

Unsigned char * changes IntPtr instead of string.

14. Rename Anonymous members

15. The structure is too complex or too large.

Void F (ref ){}

Declaration changed:

Void F (IntPtr ){}

If the pointer only obtains data:

Var intPtr = Marshal. allocHGlobal (Marshal. sizeOf (typeof (A); F (intPtr); var w = (A) Marshal. ptrToStructure (intPtr, typeof ());

If the pointer only sends data:

Var intPtr = Marshal. AllocHGlobal (Marshal. SizeOf (typeof (A); A aa; Marshal. StructureToPtr (aa, intPtr, true); F (intPtr );

 

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.