Ok if I've done this once I've done it a million bloody times. The only difference here is I'm calling CreateWindowEx() passing parameters which are parameters of a function in a DLL:
Code:
HWND GFXBase::NewWindow(HINSTANCE hInst, WNDPROC wndProc, DWORD windowStyle,
char *className, char *windowTitle, int x, int y, int width, int height)
{
this->mWindowInstance = hInst;
DWORD lastError = NULL;
char buf[120] = {0};
mWC.cbClsExtra = 0;
mWC.cbSize = sizeof(mWC);
mWC.cbWndExtra = 0;
mWC.hbrBackground = reinterpret_cast<HBRUSH> (COLOR_WINDOW);
mWC.hCursor = LoadCursor(NULL, IDC_ARROW);
mWC.hIcon = LoadIcon(NULL, IDI_APPLICATION);
mWC.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
mWC.hInstance = hInst;
mWC.lpfnWndProc = wndProc;
mWC.lpszClassName = className;
mWC.lpszMenuName = NULL;
mWC.style = CS_HREDRAW | CS_VREDRAW;
if (! RegisterClassEx(&mWC))
{
lastError = GetLastError();
sprintf(buf, "Unable to register window class [%u]", lastError);
MessageBox(NULL, buf, "GFXBase::NewWindow",
MB_OK | MB_ICONERROR | MB_TASKMODAL);
return NULL;
}
this->mWindowHandle = CreateWindowEx(NULL, className, windowTitle, windowStyle,
x, y, width, height, NULL, NULL, NULL, NULL);
if (! this->mWindowHandle)
{
lastError = GetLastError();
sprintf(buf, "Unable to create window [%u]", lastError);
MessageBox(NULL, buf, "GFXBase::NewWindow",
MB_OK | MB_ICONERROR | MB_TASKMODAL);
return NULL;
}
return this->mWindowHandle;
}
The above is in the DLL. This calls it:
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
GFXBase *gfxBase = GFXBase::CreateInstance();
HWND hWnd = NULL;
MSG msg;
hWnd = gfxBase->NewWindow(hInstance, WndProc, WS_OVERLAPPEDWINDOW, "GFXBaseClient", "GFXBase Sandbox",
0, 0, 320, 240);
if (! hWnd)
{
gfxBase->DestroyWindow();
GFXBase::FreeInstance();
return 1;
}
while (GetMessage(&msg, hWnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
gfxBase->DestroyWindow();
GFXBase::FreeInstance();
return 0;
}
Now I've debugged it to death and the parameters are coming through to NewWindow fine and when I step down to the CreateWindowEx call they remain unchanged. Still, it fails with GetLastError() returning 6 ("The Handle is invalid"). Which handle? It takes 3 and none of them apply here so they should be NULL. Right?