0_o*_*0_o 5 c++ configuration winapi entry-point visual-studio
我有这个简单的 hello world C++ 应用程序:
#include <windows.h>
#include <iostream>
using namespace std;
void test()
{
cout << "Hello world" << endl;
}
Run Code Online (Sandbox Code Playgroud)
我想用作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);
}
Run Code Online (Sandbox Code Playgroud)
更多见解可以在 Raymond Chen 的 WinMain 中找到,WinMain 只是 Win32 进程入口点的常规名称。
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |