stdcall name mangling using extern c and dllexport vs module definitions (msvc++)

后端 未结 2 1648
粉色の甜心
粉色の甜心 2020-12-10 12:09

I was trying to export a simple test function for a dll to work with an application (fyi: mIRC) that specifies the calling convention as:

int __stdcall test_         


        
2条回答
  •  臣服心动
    2020-12-10 12:52

    extern "C" has nothing to do with stdcall: it only declares that C++ name mangling (aka type-safe linkage; inclusion of type information in symbol name) is disable. You need to use it independent of whether you use C calling convention or stdcall calling convention.

    In stdcall calling convention, the callee removes the parameters from the stack. To make that safe, the exported name contains the number of bytes that the callee will remove from the stack.

    If the application you are exporting to requires that no @number suffix is added to the name, it probably means that it expects C calling convention. So you should stop declaring the function as __stdcall. When you the declare it as declspec(dllexport), you should get an undecorated name in the DLL.

    In the DEF file, you can call the function whatever you want; no additional checking is performed.

提交回复
热议问题