I created a DLL in C++ and loaded in C# with [DllImport].
Is __cdecl default in C++ when exporting without calling convention?
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
orCallingConvention.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.