www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Win32API Window and Tango

reply Zarathustra <adam.chrapkowski gmail.com> writes:
How to create WIN32Window with Tango?
Why window handle is null?

module test;
import tango.sys.win32.UserGdi;
 
extern (C) void rt_init( void delegate(Exception) dg = null );
extern (C) void rt_term( void delegate(Exception) dg = null );

extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD, int, int,
int, int, HWND, HMENU, HINSTANCE, LPVOID);
extern(Windows)HGDIOBJ GetStockObject(int);

//_____________________________________________________________________________________________________________________
//	C functions
// 

// function WinMain
//_____________________________________________________________________________________________________________________
extern (Windows) int 
WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR o_lpCmdLine,
int o_nCmdShow){

  rt_init();

	int l_result;
 
	try{
		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine, o_nCmdShow);
	}
	catch(Object o){
		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |
MB_ICONERROR);
		l_result = 0;
	}
	rt_term(); 
	return l_result;
}

// function WindowProc
//_____________________________________________________________________________________________________________________
extern (Windows) int
WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM o_lParam){
	switch(o_message){
	
		case WM_CREATE:
			return 0;
					
		case WM_CLOSE:
			PostQuitMessage(0);
			return 0;
	
		case WM_DESTROY:
			return 0;
	
		case WM_KEYDOWN:
			switch(o_wParam){
				default:
					return 0;
			}
			return 0;
	
		default:
			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
  }
}

//_____________________________________________________________________________________________________________________
//	D functions
//

// function Main
//_____________________________________________________________________________________________________________________
int 
Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR o_lpCmdLine, int
o_nCmdShow){

	// register window class
	//____________________________________________________________________
	WNDCLASS l_cWindow;
	with(l_cWindow){
		style         = CS_OWNDC;
		lpfnWndProc   = &WindowProc;
		cbClsExtra    = 0;
		cbWndExtra    = 0;
		hInstance     = hInstance;
		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
		lpszMenuName  = null;
		lpszClassName = "WINDOWCLASS";
	}
	assert(RegisterClassA(&l_cWindow));	

	// create main window
	//____________________________________________________________________
	HWND l_hWindow = CreateWindowExA(
		0,
		"WINDOWCLASS",
		"WINDOWCLASS",
		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
		100, 
		100, 
		640, 
		640,
		HWND_DESKTOP,
		cast(HMENU)null,
		o_hInstance,
		null
	);
	assert(l_hWindow);	// <- error l_hWindow is null
	
	// show window
	//____________________________________________________________________
	ShowWindow(l_hWindow, SW_SHOW); 
	UpdateWindow(l_hWindow); 

	// program main loop
	//____________________________________________________________________
	MSG l_message;
	msgsPomp:
	while(true){
		
    // check for messages  
    if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){ 
		
      // handle or dispatch messages
      if(l_message.message == WM_QUIT){ 
        break msgsPomp; 
      } 
      else{ 
        TranslateMessage(&l_message); 
        DispatchMessageA(&l_message); 
      } 
    } 
    else{
			Sleep(20);
		} 
  } 
	return l_message.wParam;
} 
Aug 27 2008
next sibling parent reply "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 27 Aug 2008 18:24:52 +0400, Zarathustra  
<adam.chrapkowski gmail.com> wrote:

 How to create WIN32Window with Tango?
 Why window handle is null?

 module test;
 import tango.sys.win32.UserGdi;
 extern (C) void rt_init( void delegate(Exception) dg = null );
 extern (C) void rt_term( void delegate(Exception) dg = null );

 extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD,  
 int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
 extern(Windows)HGDIOBJ GetStockObject(int);

 //_____________________________________________________________________________________________________________________
 //	C functions
 //

 // function WinMain
 //_____________________________________________________________________________________________________________________
 extern (Windows) int
 WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR  
 o_lpCmdLine, int o_nCmdShow){

   rt_init();

 	int l_result;
 	try{
 		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine, o_nCmdShow);
 	}
 	catch(Object o){
 		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |  
 MB_ICONERROR);
 		l_result = 0;
 	}
 	rt_term();
 	return l_result;
 }

 // function WindowProc
 //_____________________________________________________________________________________________________________________
 extern (Windows) int
 WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM  
 o_lParam){
 	switch(o_message){
 	
 		case WM_CREATE:
 			return 0;
 					
 		case WM_CLOSE:
 			PostQuitMessage(0);
 			return 0;
 	
 		case WM_DESTROY:
 			return 0;
 	
 		case WM_KEYDOWN:
 			switch(o_wParam){
 				default:
 					return 0;
 			}
 			return 0;
 	
 		default:
 			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
   }
 }

 //_____________________________________________________________________________________________________________________
 //	D functions
 //

 // function Main
 //_____________________________________________________________________________________________________________________
 int
 Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR  
 o_lpCmdLine, int o_nCmdShow){

 	// register window class
 	//____________________________________________________________________
 	WNDCLASS l_cWindow;
 	with(l_cWindow){
 		style         = CS_OWNDC;
 		lpfnWndProc   = &WindowProc;
 		cbClsExtra    = 0;
 		cbWndExtra    = 0;
 		hInstance     = hInstance;
 		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
 		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
 		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
 		lpszMenuName  = null;
 		lpszClassName = "WINDOWCLASS";
 	}
 	assert(RegisterClassA(&l_cWindow));	

 	// create main window
 	//____________________________________________________________________
 	HWND l_hWindow = CreateWindowExA(
 		0,
 		"WINDOWCLASS",
 		"WINDOWCLASS",
 		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
 		100,
 		100,
 		640,
 		640,
 		HWND_DESKTOP,
 		cast(HMENU)null,
 		o_hInstance,
 		null
 	);
 	assert(l_hWindow);	// <- error l_hWindow is null
 	
 	// show window
 	//____________________________________________________________________
 	ShowWindow(l_hWindow, SW_SHOW);
 	UpdateWindow(l_hWindow);

 	// program main loop
 	//____________________________________________________________________
 	MSG l_message;
 	msgsPomp:
 	while(true){
 		
     // check for messages
     if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){
 		
       // handle or dispatch messages
       if(l_message.message == WM_QUIT){
         break msgsPomp;
       }
       else{
         TranslateMessage(&l_message);
         DispatchMessageA(&l_message);
       }
     }
     else{
 			Sleep(20);
 		}
   }
 	return l_message.wParam;
 }

Hmm.. I have no problems with your code, it shown an empty black window with a "WINDOWCLASS" caption.
Aug 27 2008
parent reply Zarathustra <adam.chrapkowski gmail.com> writes:
Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 18:24:52 +0400, Zarathustra  
 <adam.chrapkowski gmail.com> wrote:
 
 How to create WIN32Window with Tango?
 Why window handle is null?

 module test;
 import tango.sys.win32.UserGdi;
 extern (C) void rt_init( void delegate(Exception) dg = null );
 extern (C) void rt_term( void delegate(Exception) dg = null );

 extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD,  
 int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
 extern(Windows)HGDIOBJ GetStockObject(int);

 //_____________________________________________________________________________________________________________________
 //	C functions
 //

 // function WinMain
 //_____________________________________________________________________________________________________________________
 extern (Windows) int
 WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR  
 o_lpCmdLine, int o_nCmdShow){

   rt_init();

 	int l_result;
 	try{
 		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine, o_nCmdShow);
 	}
 	catch(Object o){
 		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |  
 MB_ICONERROR);
 		l_result = 0;
 	}
 	rt_term();
 	return l_result;
 }

 // function WindowProc
 //_____________________________________________________________________________________________________________________
 extern (Windows) int
 WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM  
 o_lParam){
 	switch(o_message){
 	
 		case WM_CREATE:
 			return 0;
 					
 		case WM_CLOSE:
 			PostQuitMessage(0);
 			return 0;
 	
 		case WM_DESTROY:
 			return 0;
 	
 		case WM_KEYDOWN:
 			switch(o_wParam){
 				default:
 					return 0;
 			}
 			return 0;
 	
 		default:
 			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
   }
 }

 //_____________________________________________________________________________________________________________________
 //	D functions
 //

 // function Main
 //_____________________________________________________________________________________________________________________
 int
 Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR  
 o_lpCmdLine, int o_nCmdShow){

 	// register window class
 	//____________________________________________________________________
 	WNDCLASS l_cWindow;
 	with(l_cWindow){
 		style         = CS_OWNDC;
 		lpfnWndProc   = &WindowProc;
 		cbClsExtra    = 0;
 		cbWndExtra    = 0;
 		hInstance     = hInstance;
 		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
 		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
 		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
 		lpszMenuName  = null;
 		lpszClassName = "WINDOWCLASS";
 	}
 	assert(RegisterClassA(&l_cWindow));	

 	// create main window
 	//____________________________________________________________________
 	HWND l_hWindow = CreateWindowExA(
 		0,
 		"WINDOWCLASS",
 		"WINDOWCLASS",
 		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
 		100,
 		100,
 		640,
 		640,
 		HWND_DESKTOP,
 		cast(HMENU)null,
 		o_hInstance,
 		null
 	);
 	assert(l_hWindow);	// <- error l_hWindow is null
 	
 	// show window
 	//____________________________________________________________________
 	ShowWindow(l_hWindow, SW_SHOW);
 	UpdateWindow(l_hWindow);

 	// program main loop
 	//____________________________________________________________________
 	MSG l_message;
 	msgsPomp:
 	while(true){
 		
     // check for messages
     if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){
 		
       // handle or dispatch messages
       if(l_message.message == WM_QUIT){
         break msgsPomp;
       }
       else{
         TranslateMessage(&l_message);
         DispatchMessageA(&l_message);
       }
     }
     else{
 			Sleep(20);
 		}
   }
 	return l_message.wParam;
 }

Hmm.. I have no problems with your code, it shown an empty black window with a "WINDOWCLASS" caption.

I don't have any idea what's wrong? Tango 0.97 I'm dsss user: command line: dsss build test.d dsss.conf; [test.d] buildflags+=-L/exet:nt buildflags+=-L/su:windows:5 buildflags+=-full
Aug 27 2008
parent reply Zarathustra <adam.chrapkowski gmail.com> writes:
Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 19:07:27 +0400, Zarathustra  
 <adam.chrapkowski gmail.com> wrote:
 
 Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 18:24:52 +0400, Zarathustra
 <adam.chrapkowski gmail.com> wrote:

 How to create WIN32Window with Tango?
 Why window handle is null?

 module test;
 import tango.sys.win32.UserGdi;
 extern (C) void rt_init( void delegate(Exception) dg = null );
 extern (C) void rt_term( void delegate(Exception) dg = null );

 extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD,
 int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
 extern(Windows)HGDIOBJ GetStockObject(int);

  

 //	C functions
 //

 // function WinMain
  

 extern (Windows) int
 WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR
 o_lpCmdLine, int o_nCmdShow){

   rt_init();

 	int l_result;
 	try{
 		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine,  

 	}
 	catch(Object o){
 		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |
 MB_ICONERROR);
 		l_result = 0;
 	}
 	rt_term();
 	return l_result;
 }

 // function WindowProc
  

 extern (Windows) int
 WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM
 o_lParam){
 	switch(o_message){
 	
 		case WM_CREATE:
 			return 0;
 					
 		case WM_CLOSE:
 			PostQuitMessage(0);
 			return 0;
 	
 		case WM_DESTROY:
 			return 0;
 	
 		case WM_KEYDOWN:
 			switch(o_wParam){
 				default:
 					return 0;
 			}
 			return 0;
 	
 		default:
 			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
   }
 }

  

 //	D functions
 //

 // function Main
  

 int
 Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR
 o_lpCmdLine, int o_nCmdShow){

 	// register window class
  

 	WNDCLASS l_cWindow;
 	with(l_cWindow){
 		style         = CS_OWNDC;
 		lpfnWndProc   = &WindowProc;
 		cbClsExtra    = 0;
 		cbWndExtra    = 0;
 		hInstance     = hInstance;
 		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
 		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
 		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
 		lpszMenuName  = null;
 		lpszClassName = "WINDOWCLASS";
 	}
 	assert(RegisterClassA(&l_cWindow));	

 	// create main window
  

 	HWND l_hWindow = CreateWindowExA(
 		0,
 		"WINDOWCLASS",
 		"WINDOWCLASS",
 		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
 		100,
 		100,
 		640,
 		640,
 		HWND_DESKTOP,
 		cast(HMENU)null,
 		o_hInstance,
 		null
 	);
 	assert(l_hWindow);	// <- error l_hWindow is null
 	
 	// show window
  

 	ShowWindow(l_hWindow, SW_SHOW);
 	UpdateWindow(l_hWindow);

 	// program main loop
  

 	MSG l_message;
 	msgsPomp:
 	while(true){
 		
     // check for messages
     if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){
 		
       // handle or dispatch messages
       if(l_message.message == WM_QUIT){
         break msgsPomp;
       }
       else{
         TranslateMessage(&l_message);
         DispatchMessageA(&l_message);
       }
     }
     else{
 			Sleep(20);
 		}
   }
 	return l_message.wParam;
 }

Hmm.. I have no problems with your code, it shown an empty black window with a "WINDOWCLASS" caption.

I don't have any idea what's wrong? Tango 0.97 I'm dsss user: command line: dsss build test.d dsss.conf; [test.d] buildflags+=-L/exet:nt buildflags+=-L/su:windows:5 buildflags+=-full

I use "dmd app.d gdi32.lib". Don't know what Tango version it is, but it is bundled with DMD1.029

Yes, gdi32.lib is needed, because dmd\lib\gdi32.lib don't contain GetStockObject function. My Tango is bundled with latest DMD1.033 Later I will try swap gdi32.dll (maybe is corrupted) and compile with older Tango and DMD versions.
Aug 27 2008
next sibling parent Zarathustra <adam.chrapkowski gmail.com> writes:
Thanks Denis
I tested Tango 0.96 bundled with DMD1.033 = assertion error
            Tango 0.97 bundled with DMD1.033 = assertion error
            
Tango 0.96 bundled with DMD1.027
function tango.sys.win32.UserGdi.CreateWindowExA
(uint,char*,char*,uint,int,int,int,int,void*,void*,void*,void*) does not match
parameter types (int,char*,char*,uint,int,int,int,int,uint,void*,void*,void*)

because:
at Tango0.96 and Tango0.97 HWND_DESKTOP constant is defined as:
HWND_DESKTOP = cast(HWND)0; // void*

at Tango0.95 HWND_DESKTOP constant is defined as:
HWND_DESKTOP = (0); // uint

When I changed HWND_DESKTOP to cast(HWND)0 or just cast(HWND)null then program
works with Tango0.95 bundled with DMD1.027

I can not test Tango0.95 with DMD1.033 because last release of Tango0.95 is
bundled with DMD1.027.
Aug 27 2008
prev sibling parent Zarathustra <adam.chrapkowski gmail.com> writes:
Probably is something wrong with DMD1.033 because program also works with
DMD1.030 and Tango0.99.7.
Aug 27 2008
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 27 Aug 2008 19:07:27 +0400, Zarathustra  
<adam.chrapkowski gmail.com> wrote:

 Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 18:24:52 +0400, Zarathustra
 <adam.chrapkowski gmail.com> wrote:

 How to create WIN32Window with Tango?
 Why window handle is null?

 module test;
 import tango.sys.win32.UserGdi;
 extern (C) void rt_init( void delegate(Exception) dg = null );
 extern (C) void rt_term( void delegate(Exception) dg = null );

 extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD,
 int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
 extern(Windows)HGDIOBJ GetStockObject(int);

  

 //	C functions
 //

 // function WinMain
  

 extern (Windows) int
 WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR
 o_lpCmdLine, int o_nCmdShow){

   rt_init();

 	int l_result;
 	try{
 		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine,  

 	}
 	catch(Object o){
 		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |
 MB_ICONERROR);
 		l_result = 0;
 	}
 	rt_term();
 	return l_result;
 }

 // function WindowProc
  

 extern (Windows) int
 WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM
 o_lParam){
 	switch(o_message){
 	
 		case WM_CREATE:
 			return 0;
 					
 		case WM_CLOSE:
 			PostQuitMessage(0);
 			return 0;
 	
 		case WM_DESTROY:
 			return 0;
 	
 		case WM_KEYDOWN:
 			switch(o_wParam){
 				default:
 					return 0;
 			}
 			return 0;
 	
 		default:
 			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
   }
 }

  

 //	D functions
 //

 // function Main
  

 int
 Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR
 o_lpCmdLine, int o_nCmdShow){

 	// register window class
  

 	WNDCLASS l_cWindow;
 	with(l_cWindow){
 		style         = CS_OWNDC;
 		lpfnWndProc   = &WindowProc;
 		cbClsExtra    = 0;
 		cbWndExtra    = 0;
 		hInstance     = hInstance;
 		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
 		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
 		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
 		lpszMenuName  = null;
 		lpszClassName = "WINDOWCLASS";
 	}
 	assert(RegisterClassA(&l_cWindow));	

 	// create main window
  

 	HWND l_hWindow = CreateWindowExA(
 		0,
 		"WINDOWCLASS",
 		"WINDOWCLASS",
 		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
 		100,
 		100,
 		640,
 		640,
 		HWND_DESKTOP,
 		cast(HMENU)null,
 		o_hInstance,
 		null
 	);
 	assert(l_hWindow);	// <- error l_hWindow is null
 	
 	// show window
  

 	ShowWindow(l_hWindow, SW_SHOW);
 	UpdateWindow(l_hWindow);

 	// program main loop
  

 	MSG l_message;
 	msgsPomp:
 	while(true){
 		
     // check for messages
     if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){
 		
       // handle or dispatch messages
       if(l_message.message == WM_QUIT){
         break msgsPomp;
       }
       else{
         TranslateMessage(&l_message);
         DispatchMessageA(&l_message);
       }
     }
     else{
 			Sleep(20);
 		}
   }
 	return l_message.wParam;
 }

Hmm.. I have no problems with your code, it shown an empty black window with a "WINDOWCLASS" caption.

I don't have any idea what's wrong? Tango 0.97 I'm dsss user: command line: dsss build test.d dsss.conf; [test.d] buildflags+=-L/exet:nt buildflags+=-L/su:windows:5 buildflags+=-full

I use "dmd app.d gdi32.lib". Don't know what Tango version it is, but it is bundled with DMD1.029
Aug 27 2008
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 27 Aug 2008 19:38:52 +0400, Zarathustra  
<adam.chrapkowski gmail.com> wrote:

 Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 19:07:27 +0400, Zarathustra
 <adam.chrapkowski gmail.com> wrote:

 Denis Koroskin Wrote:

 On Wed, 27 Aug 2008 18:24:52 +0400, Zarathustra
 <adam.chrapkowski gmail.com> wrote:

 How to create WIN32Window with Tango?
 Why window handle is null?

 module test;
 import tango.sys.win32.UserGdi;
 extern (C) void rt_init( void delegate(Exception) dg = null );
 extern (C) void rt_term( void delegate(Exception) dg = null );

 extern(Windows)HWND    CreateWindowExA(DWORD, LPCSTR, LPCSTR,  



 int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
 extern(Windows)HGDIOBJ GetStockObject(int);



 //	C functions
 //

 // function WinMain



 extern (Windows) int
 WinMain(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance, LPSTR
 o_lpCmdLine, int o_nCmdShow){

   rt_init();

 	int l_result;
 	try{
 		l_result = Main(o_hInstance, o_hPrevInstance, o_lpCmdLine,

 	}
 	catch(Object o){
 		MessageBoxA(null, cast(char*)o.toString(), "Fatal Error", MB_OK |
 MB_ICONERROR);
 		l_result = 0;
 	}
 	rt_term();
 	return l_result;
 }

 // function WindowProc



 extern (Windows) int
 WindowProc(HWND o_hWindow, uint o_message, WPARAM o_wParam, LPARAM
 o_lParam){
 	switch(o_message){
 	
 		case WM_CREATE:
 			return 0;
 					
 		case WM_CLOSE:
 			PostQuitMessage(0);
 			return 0;
 	
 		case WM_DESTROY:
 			return 0;
 	
 		case WM_KEYDOWN:
 			switch(o_wParam){
 				default:
 					return 0;
 			}
 			return 0;
 	
 		default:
 			return DefWindowProcA(o_hWindow, o_message, o_wParam, o_lParam);
   }
 }



 //	D functions
 //

 // function Main



 int
 Main(HINSTANCE o_hInstance, HINSTANCE o_hPrevInstance,	LPSTR
 o_lpCmdLine, int o_nCmdShow){

 	// register window class



 	WNDCLASS l_cWindow;
 	with(l_cWindow){
 		style         = CS_OWNDC;
 		lpfnWndProc   = &WindowProc;
 		cbClsExtra    = 0;
 		cbWndExtra    = 0;
 		hInstance     = hInstance;
 		hIcon         = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
 		hCursor       = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
 		hbrBackground = cast(HBRUSH)GetStockObject(BLACK_BRUSH);
 		lpszMenuName  = null;
 		lpszClassName = "WINDOWCLASS";
 	}
 	assert(RegisterClassA(&l_cWindow));	

 	// create main window



 	HWND l_hWindow = CreateWindowExA(
 		0,
 		"WINDOWCLASS",
 		"WINDOWCLASS",
 		WS_CAPTION | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
 		100,
 		100,
 		640,
 		640,
 		HWND_DESKTOP,
 		cast(HMENU)null,
 		o_hInstance,
 		null
 	);
 	assert(l_hWindow);	// <- error l_hWindow is null
 	
 	// show window



 	ShowWindow(l_hWindow, SW_SHOW);
 	UpdateWindow(l_hWindow);

 	// program main loop



 	MSG l_message;
 	msgsPomp:
 	while(true){
 		
     // check for messages
     if(PeekMessageA(&l_message, cast(HWND)null, 0, 0, PM_REMOVE)){
 		
       // handle or dispatch messages
       if(l_message.message == WM_QUIT){
         break msgsPomp;
       }
       else{
         TranslateMessage(&l_message);
         DispatchMessageA(&l_message);
       }
     }
     else{
 			Sleep(20);
 		}
   }
 	return l_message.wParam;
 }

Hmm.. I have no problems with your code, it shown an empty black


 with a "WINDOWCLASS" caption.

I don't have any idea what's wrong? Tango 0.97 I'm dsss user: command line: dsss build test.d dsss.conf; [test.d] buildflags+=-L/exet:nt buildflags+=-L/su:windows:5 buildflags+=-full

I use "dmd app.d gdi32.lib". Don't know what Tango version it is, but it is bundled with DMD1.029

Yes, gdi32.lib is needed, because dmd\lib\gdi32.lib don't contain GetStockObject function. My Tango is bundled with latest DMD1.033 Later I will try swap gdi32.dll (maybe is corrupted) and compile with older Tango and DMD versions.

Indeed, compiling with the most recent Tango version gives an assertion failure. And it's most probably not a compiler's fault, because old Tango + new dmd shows the window for me. And gdi32.libs are the same for both releases.
Aug 27 2008