Re: HWND is NULL but GetLastError returns 0x00
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 = 0x0030; wndClass.style = 0x; wndClass.wndProc = cast(ptr)wndProc; wndClass.clsExtraBytes = 0x; wndClass.wndExtraBytes = 0x; wndClass.hInstance = kernel32.getModuleHandle(null); wndClass.hIcon = user32.loadIcon(null, 0x7F00); wndClass.hCursor = user32.loadCursor(null, 0x7F00); wndClass.hbrBackground = gdi32.getStockObject(0x); wndClass.menuName = null; wndClass.className = cast(str)clsname; wndClass.hIconSm = user32.loadIcon(null, 0x7F00); if(!user32.registerClassEx(cast(ptr)wndClass)){ user32.messageBox(null, user32.translateErrorCode(kernel32.getLastError()), cast(str)error, 0x); assert(false, Window class registring failed); } handle = user32.createWindowEx( 0, wndClass.className, cast(str)applicationcaption, 0x00CF, 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, 0x); 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-
Re: HWND is NULL but GetLastError returns 0x00
Ok thanks, My fault ;p
HWND is NULL but GetLastError returns 0x00
I have the problem with the following code in D2: CreateWindowEx returns NULL but I haven't got idea why? module test; import base; static import user32; static import kernel32; void MsgBox(immutable char [] o_str){ user32.messageBox(null, cast(str)o_str, cast(str)msg, 0x0); } struct WndClassEx{ align: dword size = 0x0030; dword style = 0x; ptr wndProc = null ; dword clsExtraBytes = 0x; dword wndExtraBytes = 0x; ptr hInstance = null ; ptr hIcon = null ; ptr hCursor = null ; ptr hbrBackground = null ; str menuName = null ; str className = null ; ptr hIconSm = null ; } class Application{ static const ptr hInstance; static const str commandLine; static this(){ hInstance = kernel32.getModuleHandle(null); commandLine = kernel32.getCommandLine(); assert(hInstance commandLine, Application initialization fail); } } extern (Windows) static dword wndProc(ptr o_hwnd, dword o_msg, dword o_wparam, dword o_lparam){ return 0; } class Window{ const ptr handle; this(){ WndClassEx wndClass; wndClass.size = 0x0030; wndClass.wndProc = cast(ptr)wndProc; wndClass.hInstance = kernel32.getModuleHandle(null); wndClass.className = cast(str)clsname; if(!user32.registerClassEx(cast(ptr)wndClass)){ user32.messageBox(null, user32.translateErrorCode(kernel32.getLastError()), cast(str)error, 0x); assert(false, Window class registring failed); } handle = user32.createWindowEx( 0, wndClass.className, cast(str)applicationcaption, 0x00CF, 0, 0, 640, 480, null, null, Application.hInstance, null ); if(handle is null){ // ERROR_SUCCESS user32.messageBox(null, user32.translateErrorCode(kernel32.getLastError()), cast(str)error, 0x); assert(handle); } user32.showWindow(handle, 0x000A); user32.updateWindow(handle); } } void main(){ try{ Window wnd = new Window(); } catch(Object o){ MsgBox(o.toString); } }
Re: HWND is NULL but GetLastError returns 0x00
-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-