简体   繁体   中英

Calling convention for an unmanaged DLL in C#

I created a DLL in C++ and loaded in C# with [DllImport].

  1. Is __cdecl default in C++ when exporting without calling convention?

  2. Is it okay to use CallingConvention.StdCall or CallingConvention.Winapi with the function __cdecl? (It worked in my test, and I don't use 'Variable Arguments')

Is __cdecl default in C++ when exporting without calling convention?

Yes.

Is it okay to use CallingConvention.StdCall or CallingConvention.Winapi with the function __cdecl ?

No. Use CallingConvention.Cdecl . Using the wrong calling convention might appear to work for some functions, but it is wrong, and at some point you will be caught out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM