Ralf, Good code and I can almost understand it too.

Walking thru it with the debugger I found that after this line of code "TProc procAddr = (TProc) GetProcAddress hInstLib, "GetConsoleWindow"

;" procAddr is zero, so hWnd is never set. I'm gonna step into it a little further to see if I can figure it out. Thanks, Tim
#include <windows.h>
#include <wincon.h>
HWND GetConsoleWindow(VOID);
HWND readWindowHandle()
{
HWND hWnd = 0;
// Windows 2000 or higher
if(_winver >= 0x0400) {
HINSTANCE hInstLib = LoadLibrary("kernel32"

;
if(hInstLib) {
typedef HWND (*TProc)(void);
TProc procAddr = (TProc) GetProcAddress(hInstLib, "GetConsoleWindow"

;
if(procAddr)
hWnd = (procAddr)();
FreeLibrary(hInstLib);
}
}
else { // Windows 9x, 98, SE, ME(?)
char szTitle[0x40] = {0};
DWORD dw = GetConsoleTitle(szTitle, 0x40);
hWnd = FindWindow("tty", szTitle);
}
return hWnd;
}