从使用stdcall的DLL创建MSVC导入库 [英] Creating an MSVC import library from a DLL that uses stdcall

查看:249
本文介绍了从使用stdcall的DLL创建MSVC导入库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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文件开始:

I started with the following def file:

LIBRARY simple.dll 
EXPORTS
  Foo

这创建了一个lib文件以下出口:

This created a lib file with the following exports:

Exports
       ordinal    name
                  _Foo

当我链接到这个库时,msvc链接器抱怨它无法找到_Foo @ 0。为了解决这个问题,我在def文件中添加了一个别名。

When I link with this library, the msvc linker complains that it can't find _Foo@0. To correct this problem, I added an alias to the def file.

LIBRARY simple.dll 
EXPORTS
  Foo
  Foo@0=Foo

这导致带有导出的lib文件

Which results in a lib file with exports

Exports
       ordinal    name
                  _Foo
                  _Foo@0

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

Now the project links without any problem. However, when I try to run it, I get the message

程序入口点Foo @ 0无法位于动态链接库simple.dll

"The procedure entry point Foo@0 could not be located in the dynamic link library simple.dll"

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

So it appears that even though I told lib.exe that Foo@0 is an alias for Foo, it still creates an import library that tries to load "Foo@0" by name.

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

Is there a way to get the import library to load "Foo" when I asked for "Foo@0"?

谢谢,

David

推荐答案

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

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


似乎LIB不接受别名形式(它只会忽略在等号之后的部分); 2)它假定DEF文件中的所有函数__cdecl。第二点在于它产生的导入库将DLL中的每个符号映射到带有下划线前缀的内部名称,即,使用导入库的链接器将尝试解析未定义的symbo l _Function到DLL中的符号函数。它不需要特别注意__stdcall调用约定。通过一些技术,我们可以使用LIB为__stdcall函数生成导入库,但调用者只能按顺序调用它们,而不能通过名称调用它们。详细信息留作练习:-)。( 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)

为我工作:)

这篇关于从使用stdcall的DLL创建MSVC导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆