用. def创建DLL来定义函数名

Creating DLL with .DEF to Define function names

本文关键字:定义 函数 DLL def 创建      更新时间:2023-10-16

我试图创建一个DLL并定义函数名与.def文件,但它似乎不工作。我的DLL头文件是:

 #ifdef ColorDLL_EXPORTS
 #define ColorDLL_API
 #endif
 int ColorSelect(int i);
Cpp文件:
#include "stdafx.h"
#include "ColorDLL.h"
#using <ColorDiologeClass.dll>
int ColorSelect(int i){
    ColorDiologeClass::Class1::ColorReturn(1);
    return 1;
}

我在解决方案资源管理器中添加了一个ColorDLL.def,并添加了一个.DEF文件,该文件看起来像这样:

LIBRARY "ColorDLL"
EXPORTS
    ColorSelect

当我使用Dumpbin/Exports时,结果是

name 
ColorSelect = ?ColorSelect@@YAHH@Z (int __cdec1 ColorSelect(int))

我看到它的名字看起来像这样

name 
ColorSelect

如何去掉=部分?

如果您使用__declspec(dllexport),则将发出修改后的名称,正如您所看到的那样。您根本不需要. def文件。删除第一个文件,对于不同的结果只使用def文件。

注意#if的两个分支都有导出