如何从构建的 DLL 中获取清晰的导出函数名称?我总是得到原始名称+乱码

发布于 2024-11-16 05:19:13 字数 2118 浏览 1 评论 0原文

注意:首先我使用的是 Visual Studio 2010。

通常我需要带有一些导出函数的 DLL,我需要从外部应用程序使用这些函数。

通常这就是我的 DLL 标头的外观...

#define DLLAPI extern "C" __declspec(dllexport)

DLLAPI BOOL WINAPI FUNCTION1(...);
DLLAPI BOOL WINAPI FUNCTION2(...);

我不会向项目或任何东西,我所做的导出它们就是在标头中添加 DLLAPI 到源文件 ofc 中的函数。

现在,当我需要从外部应用程序获取函数名称时,它给我带来了问题,因为它总是像 FUNCTION1xa1@assu79sax_ 或类似的东西......

使其标题像......的项目

// INCLUDE FILE generated by "Pelles C for Windows, version 3.00".

#ifndef _HOOK_H
#define _HOOK_H

#ifdef _HOOK_
#define HOOKAPI  __declspec(dllexport)
#else
#define HOOKAPI  __declspec(dllimport)
#endif /* _HOOK_ */

#ifndef WINAPI
#define WINAPI  __stdcall
#endif

HOOKAPI int WINAPI SampleFunction(int, int);

#endif /* _HOOK_H */

我看到一个使用 .DEF 文件并 它的 .def 文件看起来像...

EXPORTS
    SetValuesCBT
    SetValuesKey
    SetValuesMouse
    MouseProc
    KeyProc
    CBTProc

SECTIONS
    .shared READ WRITE SHARED

这会导致导出非常清晰的函数名称,就像它们被调用一样(由 dumpbin.exe 证明)顺便说一句,如果重要的话,它还有包含以下内容的 .pjj 文件...

# 
# PROJECT FILE generated by "Pelles C for Windows, version 5.00".
# WARNING! DO NOT EDIT THIS FILE.
# 

POC_PROJECT_VERSION = 5.00.1#
POC_PROJECT_TYPE = 1#
POC_PROJECT_ARGUMENTS = #
CC = pocc.exe#
AS = #
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -Tx86-coff -Ot -W1 -Ze -Gz#
ASFLAGS = -c -nologo -coff -W1 -Cu#
RCFLAGS = -r#
LINKFLAGS = -machine:ix86 -subsystem:windows kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib -dll#
WizCreator = Pelle Orinius#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#

.SILENT:

# 
# Build hook.dll.
# 
hook.dll: \
    output\DLL.obj \
    EXPORTS.DEF
    $(LINK) $(LINKFLAGS) -out:"$@" $**

# 
# Build DLL.obj.
# 
output\DLL.obj: \
    DLL.C
    $(CC) $(CCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

我不' t知道我应该如何在我的 VS 2010 项目中模拟这个,以便当我构建我的 dll 函数名称时简单而精确?

note: First of all i am using visual studio 2010.

Usually i need dll with some exported functions that i need to use from outside apps..

Normally this is how my dll header looks...

#define DLLAPI extern "C" __declspec(dllexport)

DLLAPI BOOL WINAPI FUNCTION1(...);
DLLAPI BOOL WINAPI FUNCTION2(...);

I don't add any commands to the project or anything, all i do to export them is this in the headers + add DLLAPI to functions in the source file ofc.

Now when i need to get the function name from my outside app its making me problems because its always something like FUNCTION1xa1@assu79sax_ or something like that...

I saw a project which uses .DEF file and makes its headers like...

// INCLUDE FILE generated by "Pelles C for Windows, version 3.00".

#ifndef _HOOK_H
#define _HOOK_H

#ifdef _HOOK_
#define HOOKAPI  __declspec(dllexport)
#else
#define HOOKAPI  __declspec(dllimport)
#endif /* _HOOK_ */

#ifndef WINAPI
#define WINAPI  __stdcall
#endif

HOOKAPI int WINAPI SampleFunction(int, int);

#endif /* _HOOK_H */

and it's .def file looks like...

EXPORTS
    SetValuesCBT
    SetValuesKey
    SetValuesMouse
    MouseProc
    KeyProc
    CBTProc

SECTIONS
    .shared READ WRITE SHARED

This results in very clear function names exported aka just as they are called(as proven by dumpbin.exe) btw if matters, it also has .pjj file with following content...

# 
# PROJECT FILE generated by "Pelles C for Windows, version 5.00".
# WARNING! DO NOT EDIT THIS FILE.
# 

POC_PROJECT_VERSION = 5.00.1#
POC_PROJECT_TYPE = 1#
POC_PROJECT_ARGUMENTS = #
CC = pocc.exe#
AS = #
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -Tx86-coff -Ot -W1 -Ze -Gz#
ASFLAGS = -c -nologo -coff -W1 -Cu#
RCFLAGS = -r#
LINKFLAGS = -machine:ix86 -subsystem:windows kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib -dll#
WizCreator = Pelle Orinius#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#

.SILENT:

# 
# Build hook.dll.
# 
hook.dll: \
    output\DLL.obj \
    EXPORTS.DEF
    $(LINK) $(LINKFLAGS) -out:"$@" $**

# 
# Build DLL.obj.
# 
output\DLL.obj: \
    DLL.C
    $(CC) $(CCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

I don't know how should i emulate this in my VS 2010 project so when i build my dll function names are simple and precise?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾冷 2024-11-23 05:19:13

只需使用上面所示的两个函数创建 DEF 文件,然后进入链接选项并指定使用此 def 文件。

来自 http://msdn.microsoft.com/ en-us/library/34c30xs1%28v=vs.80%29.aspx

/DEF 选项传递一个
模块定义文件 (.def) 到
链接器。只能有一个 .def 文件
指定为 LINK。有关详细信息
.def 文件,请参阅模块定义
文件。要设置此链接器选项
Visual Studio 开发
环境

  1. 打开项目的属性页对话框。详细信息请参见
    设置 Visual C++ 项目属性。
  2. 点击“链接器”文件夹。
  3. 单击“输入”属性页面。
  4. 修改模块定义文件属性。

从内部指定 .def 文件
开发环境,你应该
将其与其他项目一起添加到项目中
文件,然后指定该文件到
/DEF 选项。

Just create the DEF file as you've shown above with just your two functions and go into the link options and specify to use this def file.

From http://msdn.microsoft.com/en-us/library/34c30xs1%28v=vs.80%29.aspx

The /DEF option passes a
module-definition file (.def) to the
linker. Only one .def file can be
specified to LINK. For details about
.def files, see Module-Definition
Files. To set this linker option in
the Visual Studio development
environment

  1. Open the project's Property Pages dialog box. For details, see
    Setting Visual C++ Project Properties.
  2. Click the Linker folder.
  3. Click the Input property page.
  4. Modify the Module Definition File property.

To specify a .def file from within the
development environment, you should
add it to the project along with other
files and then specify the file to the
/DEF option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文