我不知道为什么会收到此错误:
test_project.obj:错误 LNK2019:函数 _WinMain@16 中引用的未解析外部符号“int __cdecl run(void)”(?run@@YAHXZ)
代码如下:
#include "stdafx.h"
#include "test_project.h"
#include <Windows.h>
HWND ghMainWnd = 0;
bool InitWindowsApp (HINSTANCE instanceHandle, int show);
int run();
LRESULT CALLBACK
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nShowCmd) {
if (!InitWindowsApp (hInstance, nShowCmd) )
return 0;
return run();
}
bool InitWindowsApp (HINSTANCE instanceHandle, int show) {
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = instanceHandle;
wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
wc.hCursor = LoadCursor( 0 , IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = L"BasicWndClass";
if (!RegisterClass(&wc) ) {
MessageBox(0, L"RegisterClass FAILED", 0, 0);
return false;
}
ghMainWnd = CreateWindow (
L"BasicWndClass",
L"Win32Basic",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
instanceHandle,
0);
if (ghMainWnd == 0) {
MessageBox ( 0, L"CreateWindow FAILED", 0, 0);
return false;
}
ShowWindow (ghMainWnd, show);
UpdateWindow (ghMainWnd);
return true;
}
int Run() {
MSG msg = {0};
BOOL bRet = 1;
while ((bRet = GetMessage(&msg, 0, 0, 0)) != 0) {
if (bRet == -1)
{
MessageBox(0, L"GetMessage FAILED", L"Error", MB_OK);
break;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
LRESULT CALLBACK
WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_LBUTTONDOWN:
MessageBox(0, L"Hello, World", L"Hello", MB_OK);
return 0;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
DestroyWindow(ghMainWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam);
}
在属性页->c/c++->general->additional include 目录中,我放置了包含 lib 的目录:C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
在属性页->链接器->输入->附加依赖项中,我已将完整路径放入库 C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\user32.lib
在属性页->链接器->系统->子系统中,我放置了 Windows (/SUBSYSTEM:WINDOWS)
我不知道接下来要尝试什么。