Win32 RegisterClass Error

Lutger lutger.blijdestijn at gmail.com
Sat Nov 17 04:31:13 PST 2007


GaboonViper wrote:
> Hi,
> 
> I've been working with win32 libraries for a few weeks. I'm trying to 
> build a GUI framework, as I'm not satisfied with the ones currently 
> available.
> 
> So currently I'm working on detecting win32 errors and I've found that 
> RegisterClass is giving me an Error Code 2, which apparently translates 
> to "The system cannot find the file specified".
> 
> It doesn't really seem to matter what I change. It always gives me the 
> same problem. I'm using the win32 headers from the bindings project on 
> dsource.org. However I tried the std.c.windows.windows with the same 
> results.
> 
> Below is the code that reproduces the problem. It's basically a slice of 
> one of the tutorials on dsource.org.
> 
> Can anyone tell me what causes this error? And how to fix it?
> 
> Boyd.

The problem is that there is no problem. If you check the return value 
of RegisterClass, you'll see that it works fine. The reason you get this 
error from GetLastError, is because the last error is only defined when 
an error actually occured. It doesn't tell you if a function executed 
succesfully.


A note about the message pump from msdn:

<quote>

Warning

Because the return value can be nonzero, zero, or -1, avoid code like this:

while (GetMessage( lpMsg, hWnd, 0, 0)) ...

The possibility of a -1 return value means that such code can lead to 
fatal application errors. Instead, use code like this:

BOOL bRet;

while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
{
     if (bRet == -1)
     {
         // handle the error and possibly exit
     }
     else
     {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
     }
}

</quote>


More information about the Digitalmars-d-learn mailing list