“hInstance”未定义。C++ Win32应用程序
Win32应用程序。在MyRegisterClass中,wc.hInsance=hInstance。显然,hInstane是一个未定义的标识符。为什么?我正在使用Visual Studio 2013,我正在学习乔纳森的《海港》一书中关于游戏编程的内容 代码“hInstance”未定义。C++ Win32应用程序,c++,winapi,hwnd,hinstance,C++,Winapi,Hwnd,Hinstance,Win32应用程序。在MyRegisterClass中,wc.hInsance=hInstance。显然,hInstane是一个未定义的标识符。为什么?我正在使用Visual Studio 2013,我正在学习乔纳森的《海港》一书中关于游戏编程的内容 代码 您的程序中有一个游离分号: ATOM MyRegisterClass(HINSTANCE hInstance); { // <-- Delete this 尝试删除它,看看它是否修复了问题 希望这有帮助 代码的结尾应该是: } ATO
您的程序中有一个游离分号:
ATOM MyRegisterClass(HINSTANCE hInstance); { // <-- Delete this
尝试删除它,看看它是否修复了问题
希望这有帮助 代码的结尾应该是:
}
ATOM MyRegisterClass(HINSTANCE hInstance) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE.c_str();
wc.hIconSm = NULL;
return ::RegisterClassEx(&wc);
}
注:
MyRegisterClass定义中没有分号
MyRegisterClass末尾只有一个大括号
在MyRegisterClass定义上方添加右大括号
这种方式代码编译正确。
嵌套函数在C++中是不允许的。}
ATOM MyRegisterClass(HINSTANCE hInstance) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE.c_str();
wc.hIconSm = NULL;
return ::RegisterClassEx(&wc);
}