Check the return value from RegisterClassEx. Use sark''s snippet to format the error message or pass it along to the func I laid out. Let windows tell you what the errno means rather than guess at it yourself.
Here''s the full listing of the adaptation that I was able to get running.
#include <windows.h>VOID ReportError(DWORD errno){ LPVOID lpMsgBuf; DWORD msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL , errno , MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) , (LPTSTR) &lpMsgBuf , 0, NULL); if ( msglen > 0 ) { MessageBox(GetActiveWindow(), lpMsgBuf, TEXT("Error Report"), MB_OK + MB_ICONEXCLAMATION); } LocalFree( lpMsgBuf );}HINSTANCE g_hInstance;TCHAR g_cAppName[] = TEXT("mrbeaner");LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ if (msg == WM_DESTROY) { PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam);}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrvInst,LPSTR lpCmdLine,int nShowCmd){ WNDCLASSEX wc; g_hInstance = hInstance; MSG Msg; HWND hWnd; wc.cbSize=sizeof(wc); wc.cbClsExtra = 0; //NULL; wc.cbWndExtra= 0; // NULL; wc.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = "DX"; wc.lpszMenuName = 0; wc.style=CS_VREDRAW | CS_HREDRAW; RegisterClassEx(&wc); hWnd = CreateWindowEx(0L, //NULL, wc.lpszClassName, //This is the class name of the Widnows class g_cAppName, //This is The captoin of teh window WS_OVERLAPPEDWINDOW, //These are style flags CW_USEDEFAULT, CW_USEDEFAULT, //Initial Startup position 512, 512, //The actual Window "Size" NULL, //Handle to the parent window NULL, //Handle to a amenu hInstance, //The handle to the instance of our app NULL //Nothing. ); if ( hWnd == NULL ) { ReportError(GetLastError()); PostQuitMessage(0); // to keep with the original } ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); while ( GetMessage (&Msg, NULL, 0, 0) ) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam ;}