RegisterClassEx problem...

Started by
16 comments, last by chollida1 19 years, 4 months ago
Hello. When I try to register my windows class using RegisterClassEx in my program I get an error which GetLastError tells me is error 120. This apparently is: This function is not supported on this system. I find this confusing as an identical call in one of the programs in the SDK samples works fine? The only difference between the two is that my project is built using UNICODE. Could this affect the outcome of function calls with identical input? This is the code:

WNDCLASSEX wc = {sizeof(WNDCLASSEX),
                       CS_CLASSDC,
                       0L,
                       0L,
                       GetModuleHandle(NULL),
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       L"Star Chart",
                       NULL};

RegisterClassEx(&wc);

How can it be that this identical code works fine in one project and not in the other? Any ideas would be greatly appreciated because I have been at this for 6 hours now with no success...:( Thanks in advance. Mark Coleman
Advertisement
wheres the wndproc?
Sorry that was a typo... The WndProc is directly above in the code so it should be able to see it...

The code above is in a MakeWindow function...

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){     switch(msg)     {          case WM_DESTROY:               PostQuitMessage(0);               return 0;          case WM_PAINT:          case WM_TIMER:          case WM_GRAPHNOTIFY:          case WM_LBUTTONDOWN:          case WM_NEXTSCREEN:          case WM_STARTSCREEN:               HandleEvent(msg, wParam, lParam);               break;          case WM_DISPLAYCHANGE:               break;          case WM_CHAR:               {                    if(wParam == VK_ESCAPE)                    {                         PostMessage(hWnd, WM_CLOSE, 0, 0);                    }                    else                    {                         PostMessage(hWnd, WM_NEXTSCREEN, 0, 0);                    }               }               break;     }     return DefWindowProc(hWnd, msg, wParam, lParam);}HRESULT MakeWindow(HINSTANCE hInstance){    WNDCLASSEX wc = {sizeof(WNDCLASSEX),                       CS_CLASSDC,                       MsgProc,                       0L,                       GetModuleHandle(NULL),                       NULL,                       NULL,                       NULL,                       NULL,                       L"Star Chart",                       NULL};     RegisterClassEx(&wc);     ... rest of windows code ...}


I have been working on this all night now and nothing?

I just don't get it?!

Any suggestions no matter what will be appreciated at this point, thanks in advance for any help.

Mark Coleman

[Edited by - mrmrcoleman on November 29, 2004 5:46:31 AM]
I have had a bit of a development but the result is still as confusing...

I thought that maybe GetModuleHandle could be causing the error so I set-up up a MessageBox like this...

SetLastError(0);GetModuleHandle(NULL);WCHAR error[80];swprintf(error, L"Error Code: %i", GetLastError());MessageBox(0, error, L"Error Code", 0);


And I get the same error 120 - 'This function is not supported on this system'

What does this mean? Surely this call must be supported? Has anybody come across this problem before?

Thanks for any help, I think I might be gettign there but I feel just as confused!

Mark Coleman
you only have 1 int between your MsgProc (WNDPROC) and "GetModuleHandle(NULL)" (instance handle) entries in the WNDCLASSEX struct. you need one for the extra class info and one for the extra window info. or is that another copy/paste error?
Thanks for the input anonymous but I am afraid that is another typo!!

This is driving me insane! Please somebody help....

Mark Coleman
Did you compare if "RegisterClassEx" returned zero before you called "GetLastError"? As "GetLastError" only returns a reasonable value when the function called prior to it terminated with an error state.

/* * Correct way */if (RegisterClassEx(&wc) == 0)   {    error = GetLastError();   }/* * Wrong way */RegisterClassEx(&wc);error = GetLastError();
I wasn't doing that because I was using SetLastError(0) just before the call, but I see what you mean. I tried it and the function is failing as expected.

Could this be something external to the code? Because it almost has to be now. Perhaps compiler settings, could these affect anything?

Thanks for any help.

Mark Coleman

Instead of using GetModuleHandle(NULL) for the HINSTANCE value in the WNDCLASSEX struct, use the value passed as the first parameter to your WndMain() function. I.e.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ 	MakeWindow(hInstance);	...} HRESULT MakeWindow(HINSTANCE hInstance){	WNDCLASSEX wc = {sizeof(WNDCLASSEX),	                       CS_CLASSDC,	                       0L,	                       0L,	                       hInstance  // <--- Just do this	                       NULL,	                       NULL,	                       NULL,	                       NULL,	                       L"Star Chart",	                       NULL}; 	RegisterClassEx(&wc);}
Aprosenf,

Thanks for the tip mate but I tried it and there is no change, I still get the same error.

It may be of use to know that identical calls in the SDK samples work fine... It must be something to do with my build environment would you think?

I have no idea how this would affect win32 function calls but could it? It must be significant (or at least good news) that the function will work in other workspaces?

Again any help is massively appreciated, this is breaking new personal records here... 19 hours and still no progress, or sleep for that matter.

Mark Coleman

This topic is closed to new replies.

Advertisement