Creating an MSVC import library from a DLL that uses stdcall

前端 未结 1 952
感情败类
感情败类 2020-12-19 07:51

I have a dll that exports

extern \"C\" __declspec(dllexport) int __stdcall Foo( void );

A dump of the dll shows

***********         


        
1条回答
  •  时光说笑
    2020-12-19 08:32

    You had the right idea trying to use an alias ...

    "it seems LIB does not accept aliased forms (it will simply ignore the part after the equal-sign); 2) it assumes all functions in the DEF file __cdecl. The second point lies in the fact that the import library it produces will map each symbol in the DLL to an internal name with an underscore prefixed, i.e., the linker using the import library will try to resolve an undefined symbol _Function to the symbol Function in the DLL. It takes no special care of the __stdcall calling convention. With some techniques we could use LIB to produce import libraries for __stdcall functions, but the caller could only call them by ordinal, not by name. The details are left as an exercise :-)." (http://wyw.dcweb.cn/stdcall.htm)

    Instead of using an alias use an ordinal: (using your example):

    LIBRARY simple.dll 
    EXPORTS
         Foo
         Foo@0    @2 ;(from your dumpbin)
    

    Worked for me :)

    0 讨论(0)
提交回复
热议问题