bool Window::show(const GUI::Application *const app)
{
WNDCLASSEXW windowClass = { 0 };
windowClass.cbSize = sizeof(WNDCLASSEXW);
windowClass.lpfnWndProc = m_WindowProc;
windowClass.hInstance = app->getInstance();
// Load standard cursor
if (!(windowClass.hCursor = ::LoadCursorW(NULL, IDC_ARROW)))
{
return false;
}
windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
windowClass.lpszClassName = app->getAppId().c_str();
// Register window class with system
if (!::RegisterClassExW(&windowClass))
{
return false;
}
OutputDebugStringW(L"Registered window class");
// Actually create the window
m_handle = ::CreateWindowExW(
0,
windowClass.lpszClassName,
m_title.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
m_width, m_height,
NULL,
NULL,
app->getInstance(),
NULL
);
if (!m_handle)
{
DisplayErrorMessage(GetLastError());
return false;
}
OutputDebugStringW(L"Created window");
::ShowWindow(m_handle, app->getShowCmd());
OutputDebugStringW(L"ShowWindow executed, going into message loop");
MSG msg = { 0 };
while (::GetMessageW(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
// Cleanup resources
::UnregisterClassW(windowClass.lpszClassName, app->getInstance());
return true;
}
如果我在第28行上更改为
windowClass.lpszClassName
,则该应用程序用错误代码1407崩溃。为什么会发生这种情况?他们正在访问完全相同的数据,并且在第15行的第一个呼叫和第28行上的第二个调用之间没有修改字符串。 请注意:我知道与该主题有关的其他论坛上也存在问题,但是这些答案实际上都没有解释为什么一行奏效另一行,这是我在此问题中所寻找的。
遵循
mmsdn,第二个参数是类型
app->getAppId().c_str()
,它代表着
gong的pointer,to
c
onstant