Calling conventions

suggest change

Several calling conventions specify who pops arguments from the stack (caller or callee), how arguments are passed, and in what order. C++ uses Cdecl by default, but DllImport defaults to StdCall on Windows, which is what the Windows API uses. Match one side to the other:

extern "C" __declspec(dllexport) int __stdcall add(int a, int b)
[DllImport("myDLL.dll")]
extern "C" __declspec(dllexport) int /*__cdecl*/ add(int a, int b)
[DllImport("myDLL.dll", CallingConvention = CallingConvention.Cdecl)]

If you want to use a function with Cdecl calling convention and a mangled name, your code will look like this:

__declspec(dllexport) int add(int a, int b)
[DllImport("myDLL.dll", CallingConvention = CallingConvention.Cdecl,
           EntryPoint = "?add@@YAHHH@Z")]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents