-1

I am trying to link against a dll, which is accompanied by a header file. Since there were no *.lib file available, I made one by manually creating a *.def file (Ref)

Now the problem is, my test program is __cdecl and the methods in the dll are __stdcall. Is there a way to force __stdcall for specific methods when they are dynamically linked?

Even though its not an option, tried changing the calling convention (/Gd) to /Gz, but the name mangling came up saying the linker failed to find the slightly mangled method as shown below.

LNK2019 unresolved external symbol _TSTInitialize@24 referenced in function

The function signature in header file is,

#define TSTPERC_API /*__declspec( dllimport ) __stdcall */  

TSTHandle cOpts;

    //call native methods
    TSTFunctionResult cResult = ::TSTInitialize(
        p_strPathToLib.c_str(), p_strConfigStruct.c_str(), p_strLic.c_str(),
        p_strRFU1.c_str(), p_strRFU2.c_str(), &cOpts );
Jimson James
  • 2,937
  • 6
  • 43
  • 78
  • 1
    The .def entry should probably be `TSTInitialize = TSTInitialize`. Bit of a guess when we don't know the exported name. – Hans Passant Mar 02 '20 at 21:03
  • well, sholdn't it be TSTInitialize=_TSTInitialize@24? i got it uptill _TSTInitialize but the @24 seems to get stripped off! Any idea? – Jimson James Mar 03 '20 at 14:41

1 Answers1

0

Well, you don't force stdcall on methods with incorrect .def or incorrect .lib files.

The @24 in this case is the bytes on the stack the callee needs to cleanup. So there is no way around stripping it off (in case you do, then there is no way for the callee to know how many bytes to cleanup from the stack!! ).

The real problem was with the *.def file I created. The syntax is the other way around in my comment to @hans-passant,

TSTInitialize@24=TSTInitialize

This will make the correct export symbol, _TSTInitialize@24 in the lib file linker is looking for. This helps reverting the program to use /Gd instead of /Gz

Jimson James
  • 2,937
  • 6
  • 43
  • 78