最近用如下程序,Test函数里面会进行几次new操作。发现malloc会返回NULL。不知道为什么。把Test放到while(true)里就可以了,这是为什么呢。
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 在此放置代码。 MSG msg; HACCEL hAccelTable;
// 初始化全局字符串 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_TERRAIN, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); Test();
// 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; }
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TERRAIN));
// 主消息循环: while(true){
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message != WM_QUIT) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else
Test(); break; } }
return (int) msg.wParam;}