How to call C ++ written in C ++ DLL

xiaoxiao2021-03-05  20

Transfer from: 9CBS

C has accumulated a large number of dynamic connection libraries through so many years of development, and can greatly improve the development speed of the entire application if they can apply these functions in the .NET environment. People who use C programming must not feel unfamiliar with the pointer, because the function interface in C may define a position pointer, and only in the declaration of unsafe code can be used in the declaration of unsafe codes. If you want C DLL support to call in C #, you need to use the following format in the declaration of the C interface: Extern "C" __declspec (dllexport) void __stdcall popmessage (char * message) {MessageBox (null, message , "C Message from C #!", MB_OK);} and use the following import compiled DLL in the C # class declaration, for example: [DLLIMPORT ("Test.dll", Callingconvention = CALLINGCONVENTION.CDECL)] Public Static Extern Void Message (String Themessage); DllImport ( "test.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void Func2 (string theMessage); [DllImport ( "test.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void Func3 (string theMessage) ; Then you can call the way to declare above in your C # class.

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

New Post(0)