我试图在DLL中隐藏WinMain函数,以避免一次又一次地输入大量代码。
我将wWinMain从DLL中导出,方法是将它声明为
extern "C" int WINAPI wWinMain( ... ) { // repetitive code here }
并使用链接器选项/EXPORT:wWinMain,但是当我试图在另一个项目中使用导入库时,我会得到错误。
函数LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _‘`WinMain@16在函数__tmainCRTStartup`中引用
备注:我确实想使用GUI界面,我知道当您定义main而不是WinMain函数时,这是常见的错误。另外,我在两个项目中启用了UNICODE支持。我该怎么办?
发布于 2010-12-29 06:22:19
这是不可能的,链接器只能将EXE的入口点设置为EXE中的函数。将DLL中的wWinMain()重命名为其他内容。在链接到EXE的源代码文件中编写一个wWinMain(),只需调用DLL的导出函数即可。
发布于 2016-02-08 00:03:25
// ...somewhere in a .cpp file within my .dll's sources...
#define WinMain WinMainOld // ...to suppress Win32 declaration of WinMain
#include <windows.h>
#undef WinMain // ...so that WinMain below is not replaced
. . .
#pragma comment(linker, "/export:_WinMain@16") // ...to export it from .dll
extern "C" // ...to suppress C++ name decoration
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR pCmdLine, int nCmdShow)
{
. . .
}发布于 2010-12-29 04:31:35
应该在动态链接库中使用WinMain吗?不应该是DllMain吗?
https://stackoverflow.com/questions/4540129
复制相似问题