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

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

本文介绍了从使用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 ...

而不是使用别名使用序数:(使用你的例子):

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导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:50