HWND is NULL but GetLastError returns 0x00

Zarathustra adam.chrapkowski at gmail.com
Sat Oct 17 03:55:09 PDT 2009


I filled out all fields of wndclassex and operands of createWindowEx exactly the same like in identical (working) C program, and there are still the same problem.
//________________________________
void main(){
  try{
    ptr handle;
    //Window wnd = new Window();
    WndClassEx wndClass;

    wndClass.size          = 0x00000030;
    wndClass.style         = 0x00000000;
    wndClass.wndProc       = cast(ptr)&wndProc;
    wndClass.clsExtraBytes = 0x00000000;
    wndClass.wndExtraBytes = 0x00000000;
    wndClass.hInstance     = kernel32.getModuleHandle(null);
    wndClass.hIcon         = user32.loadIcon(null, 0x00007F00);
    wndClass.hCursor       = user32.loadCursor(null, 0x00007F00);
    wndClass.hbrBackground = gdi32.getStockObject(0x00000000);
    wndClass.menuName      = null;
    wndClass.className     = cast(str)"clsname";
    wndClass.hIconSm       = user32.loadIcon(null, 0x00007F00);

    
    if(!user32.registerClassEx(cast(ptr)&wndClass)){
      user32.messageBox(null, user32.translateErrorCode(kernel32.getLastError()), cast(str)"error", 0x00000000);
      assert(false, "Window class registring failed");
    }

    handle = user32.createWindowEx(
      0,
      wndClass.className,
      cast(str)"<applicationcaption>",
      0x00CF0000,
      0,
      0,
      640,
      480,
      null,
      null,
      kernel32.getModuleHandle(null),
      null
    );
    
    if(handle is null){
      // ERROR_SUCCESS
      user32.messageBox(null, user32.translateErrorCode(kernel32.getLastError()), cast(str)"error", 0x00000000);
      assert(handle);
    }
  }
  catch(Object o){
    MsgBox(cast(char[])o.toString);
  }
}
//________________________________

div0 Wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Zarathustra wrote:
> 
> > I have the problem with the following code in D2:
> > CreateWindowEx returns NULL but I haven't got idea why?
> >
> 
> <snip>
> 
> That's because your are not properly processing all of the messages that
> are involved in window creation.
> 
> See:
> 
> http://msdn.microsoft.com/en-us/library/ms632635(VS.85).aspx
> 
> or better yet, have a look at my port of atlwin.h:
> 
> http://www.sstk.co.uk/atlWinD.php
> 
> all of this tedious shit has been done before.
> 
> - --
> My enormous talent is exceeded only by my outrageous laziness.
> http://www.ssTk.co.uk
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iD8DBQFK2Pq7T9LetA9XoXwRAqHlAKDPIZwXCWSvjNNviUX4SEguGFA+awCgoV7j
> VHP6w/x+jpQ42lOhyYxN0/o=
> =xX0G
> -----END PGP SIGNATURE-----



More information about the Digitalmars-d-learn mailing list