1
votes

I have an already built static library on Windows VS2012 (.lib), compiled with the stdcall convention. When I say "already built", I mean unfortunatedly I cannot rebuild it with the calling convention of my choice.

Is it possible to call a function from this library from a code compiled with cdecl convention ? Or at least do some kind of wrapper ?

I am not sure it is possible (after browsing SO, I am in fact almost convinced this is totally impossible) but some guy here vaguely mentioned there might be a kludge. Any idea ?

1
Edit the library's .h file(s) and put __stdcall in the function prototypes. Send your changes back to the library owner so you only have to do this once. - Hans Passant
Maybe I wasn't clear: the library's functions already have the __stdcall qualifier in the header and were compiled with it. I wish to call them from a __cdecl function in another module (mine). - GaTTaCa
Then you only have an imaginary problem. - Hans Passant
No. I will be more specific: I would like to reuse some thirdparty libraries (namely Nvidia's implementation of OpenCL libraries - found in the drivers) in my own project. Alas the libs are built with the stdcall convention thus not working with my cdecl project. - GaTTaCa
Then there must be a tooling issue -- there is no problem for modern compilers to compile cdecl functions that call stdcall functions and vice versa. - Björn Lindqvist

1 Answers

2
votes

In the header for your static library, declare the imported functions as extern <return_type> __stdcall. See more about calling convention attributes on MSDN: https://msdn.microsoft.com/en-us/library/zxk0tw93.aspx