在stdafx.h文件中开始部分添加以下代码:
// Removing the precompiler secure warnings, disable the warnings
#define _AFX_SECURE_NO_WARNINGS // MFC
#define _AFX_SECURE_NO_DEPRECATE // MFC
#define _ATL_SECURE_NO_WARNINGS // ATL
#define _ATL_SECURE_NO_DEPRECATE // ATL
#define _CRT_SECURE_NO_WARNINGS // C
#define _CRT_SECURE_NO_DEPRECATE // C
#define _CRT_NONSTDC_NO_WARNINGS // CPOSIX
#define _CRT_NONSTDC_NO_DEPRECATE // CPOSIX
#define _SCL_SECURE_NO_WARNINGS // STL
#define _SCL_SECURE_NO_DEPRECATE // STL
// Define application entry point
#if !defined(_UNICODE) && !defined(UNICODE)
#define ENTRY ""
#else
#define ENTRY "w"
#endif
#pragma comment(linker, "/ENTRY:" ENTRY "WinMainCRTStartup")
其余优化方法:
#include <windows.h>
//自定义加载的库
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"msvcrt.lib")
//自定义函数入口
#pragma comment(linker, "/ENTRY:EntryPoint")
//自定义对齐方式
#pragma comment (linker, "/ALIGN:512")
#pragma comment(linker, "/FILEALIGN:512")
// 优化选项
#pragma comment(linker, "/opt:nowin98")
#pragma comment(linker, "/opt:ref")
#pragma comment (linker, "/OPT:ICF")
// 合并区段
#pragma comment(linker, "/MERGE:.rdata=.data")
#pragma comment(linker, "/MERGE:.text=.data")
#pragma comment(linker, "/MERGE:.reloc=.data")
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow ) ;
void EntryPoint()
{
ExitProcess(WinMain(GetModuleHandle(NULL), NULL,
GetCommandLine(), SW_SHOWNORMAL));
}