我有这个简单的 hello world C++ 应用程序:
#include <windows.h>
#include <iostream>
using namespace std;
void test()
{
cout << "Hello world" << endl;
}
我想使用
test
作为我的自定义入口点。到目前为止,我尝试将 Linker -> Advanced -> Entrypoint
设置为 test
但出现了很多 lnk2001 错误。是否可以以某种方式删除任何 main() wmain() WinMain() 并仅通过 Visual studio 设置使用我的函数?
在 Windows 应用程序中使用自定义入口点可以绕过整个 CRT 启动和全局 C++ 初始化。因此,它不需要使用 CRT,并关闭依赖于 CRT 的编译器功能,例如
/GS
缓冲区检查和其他 /RTC
运行时错误检查。
以下是具有自定义入口点的最小应用程序示例
test
。
#include <sdkDdkVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// compile with /GS- lest
// LNK2001: unresolved external symbol @__security_check_cookie@4
//#pragma strict_gs_check(off)
// turn off /RTC*
#pragma runtime_checks("", off)
#pragma comment(linker, "/nodefaultlib /subsystem:windows /ENTRY:test")
int __stdcall test(void)
{
OutputDebugStringA("custom /entry:test\n");
ExitProcess(0);
}
更多见解可以在 Raymond Chen 的文章中找到 WinMain 只是 Win32 进程入口点的传统名称。
如果有人仍然感兴趣,请检查此链接