I've just recently returned to WINAPI programming in C++, but now in Vista. I'm having a problem creating a window. According to GetLastError() windows cannot find the class. Clearly the class has been registered (in the same module of course) and I'm using the same exact name for both lpszClassName and the class parameter in the CreateWindow function. I just don't see the problem.
Code:#include <Windows.h> UINT msg_is_server = NULL; UINT msg_transmit = NULL; LRESULT CALLBACK ServerWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == msg_is_server) { BOOL *bRet = (BOOL*) wParam; *bRet = TRUE; } else { BOOL *bRet = (BOOL*) wParam; *bRet = FALSE; } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LPCWSTR IPC_SERVER = L"IPCServer"; WNDCLASSEX wcx; MSG msg; HWND hWnd; msg_is_server = RegisterWindowMessage((LPCWSTR) L"IPC_IsServer"); msg_transmit = RegisterWindowMessage((LPCWSTR) L"IPC_Transmit"); wcx.cbSize = sizeof(WNDCLASSEX); wcx.style = 0; wcx.cbWndExtra = 0; wcx.cbClsExtra = 0; wcx.hCursor = NULL; wcx.hIcon = NULL; wcx.hIconSm = NULL; wcx.lpszClassName = IPC_SERVER; wcx.lpfnWndProc = ServerWndProc; wcx.lpszMenuName = NULL; wcx.hbrBackground = NULL; if (!RegisterClassEx(&wcx)) { MessageBox(NULL, (LPCWSTR) L"Unable to register IPCServer window class.", (LPCWSTR) L"Error", MB_OK); return 0; } hWnd = CreateWindow(IPC_SERVER, (LPCWSTR)L"IPCServer", WS_SYSMENU | WS_CAPTION, 20, 20, 20, 20,HWND_MESSAGE, NULL, hInstance, NULL); if (!hWnd) { DWORD err = GetLastError(); MessageBox(NULL, (LPCWSTR) L"Unable to create IPCServer window.", (LPCWSTR) L"Error", MB_OK); return err; } while (GetMessage(&msg, hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }




Reply With Quote