C # Call C function (DLL) Parameters

Source: Internet
Author: User

Memo:

1. The C function parameter is a string char *. If it is an input parameter, it corresponds to string or StringBuilder in C #; if it is an output parameter, it corresponds to StringBuider in C;

 

2. The C function parameter is a struct pointer, which must be defined in C. For input parameters, myfunction (MyStruct mystruct) or myfunction (ref MyStruct mystruct) can be used in C #. For output parameters, myfunction (ref MyStruct mystruct) is used in C ). When multiple functions use the MyStruct parameter, if one function uses ref, other functions also use ref, whether it is an output parameter or not. Otherwise, a memory error is prompted during running. That is, we should try to ensure the consistency of parameters of the same struct type defined in C.

 

3. The C function cannot return an array, but can encapsulate the array as a member of the struct. by returning the struct result, the returned array is obtained.

 

Other references:

Platform call P-INVOKE (1) -- (basic): http://blog.csdn.net/sdl2005lyx/article/details/6796037

Platform call P-INVOKE (2) -- (Mail string):

Http://blog.csdn.net/sdl2005lyx/article/details/6799495

 

Platform call P-INVOKE (3) -- (Mail structure):

Http://blog.csdn.net/sdl2005lyx/article/details/6801113

 

Platform call P-INVOKE advanced (1) -- (Mail contains two-dimensional array structure):

Http://blog.csdn.net/sdl2005lyx/article/details/6998969

Related Article

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.