gpt4 book ai didi

dll - 从使用 stdcall 的 DLL 创建 MSVC 导入库

转载 作者:行者123 更新时间:2023-12-04 15:16:11 25 4
gpt4 key购买 nike

我有一个导出的 dll

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

dll 的转储显示
******************************************************************************
Section: Exports
File Offset: 00001400 (5120)
Flags: 00000000
Time Stamp: 00000000
Major Version: 0000
Minor Version: 0000

Exports from simple.dll
3 exported name(s), 3 export addresse(s). Ordinal base is 1.
Sorted by Name:
RVA Ord. Hint Name
-------- ---- ---- ----
00002104 3 0000 std::nothrow
00001258 2 0001 Foo
000020F8 1 0002 ___CPPdebugHook

******************************************************************************

我从以下 def 文件开始:
LIBRARY simple.dll 
EXPORTS
Foo

这创建了一个具有以下导出的 lib 文件:
Exports
ordinal name
_Foo

当我链接到这个库时,msvc 链接器提示它找不到 _Foo@0。为了解决这个问题,我在 def 文件中添加了一个别名。
LIBRARY simple.dll 
EXPORTS
Foo
Foo@0=Foo

这导致带有导出的 lib 文件
Exports
ordinal name
_Foo
_Foo@0

现在项目链接没有任何问题。但是,当我尝试运行它时,我收到消息

“无法在动态链接库 simple.dll 中找到过程入口点 Foo@0”

所以看起来即使我告诉 lib.exe Foo@0 是 Foo 的别名,它仍然会创建一个导入库,尝试按名称加载“Foo@0”。

当我要求“Foo@0”时,有没有办法让导入库加载“Foo”?

谢谢,

大卫

最佳答案

您尝试使用别名的想法是正确的......

"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)



而不是使用别名使用序数:(使用您的示例):
LIBRARY simple.dll 
EXPORTS
Foo
Foo@0 @2 ;(from your dumpbin)

为我工作:)

关于dll - 从使用 stdcall 的 DLL 创建 MSVC 导入库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2393178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com