C # Call the parameter problem of API and C ++ DLL

zhaozj2021-02-16  102

If I want to call an API, one of the parameters is a char ** type, how should I call in C #?

___________________________________________________________________________________________

With StringBuilder, it is a string group type. When doing an API function parameter, it is also submitted an address, which is very in line with the requirements of the landlord! The type inside C # and C is not one of them. To see what it will eventually, such as a string? Address? Numerical? Sometimes, there can be a lot of types of corresponding to it! You try more!

If it is a string, you can use a structure to use StringBuilder to be the easiest way! C # Mold the Windows API with the API call in the VC, the mechanism of fixed parameter type is not too identical!

It is necessary to see what kind of parameters that the API function needs to give C # parameters! If it is to be modified, half of the address to the API function, such as an OUT or INTPTR type, or is a numerical type with this pass reference. If you don't need to modify, just give it to some data types of the value to it!

Another basic method for the Windows API is:

At the top of the class file

[DLLIMPORT ("User32.dll (may also be another DLL, even you do it yourself C DLL)", entrypoint = "API function"] public static extern int API function (parameter list);

Then in other places, you can quote this function, it seems to be the same as an ordinary external function!

Remember the top added

Using system.runtime.interopservices; using system.text; otherwise identifying the DLLIMPORT method, you can't identify the StringBuilder class!

转载请注明原文地址:https://www.9cbs.com/read-10771.html

New Post(0)