I am writing the windows application. using Windows WIN32. I want to use the third party DLL it build using __stdcall. but I am using __cdecl for my build. so it is not compliable to use both in same program. is there any method to do that?
in library .h file defined the call faction like this.
#define CALLING_DECLARE extern "C" HRESULT WINAPI
CodePudding user response:
While you can instruct the compiler to use a default calling convention (see /Gd, /Gr, /Gv, /Gz (Calling Convention)) you can still override that default by explicitly declaring the calling convention on each function declaration.
If you have set your project to use __cdecl
by default you will have to mark imports from a DLL compiled using __stdcall
as such, so as to not inherit the project defaults.
You can mix any number of calling conventions in a project without any issues, so long as the calling convention set at the function declaration (either explicitly or by using the default) matches the calling convention used by the implementation.