如何从构建的 DLL 中获取清晰的导出函数名称?我总是得到原始名称+乱码
注意:首先我使用的是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用上面所示的两个函数创建 DEF 文件,然后进入链接选项并指定使用此 def 文件。
来自 http://msdn.microsoft.com/ en-us/library/34c30xs1%28v=vs.80%29.aspx
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