1234567891011121314151617181920212223242526
HWND MyGetConsoleWindow() { typedef HWND (WINAPI* fnGetConsoleWindow)(); HMODULE hDll = LoadLibrary("Kernel32.dll"); if (hDll == NULL) { // error: see GetLastError() return NULL; } HWND res = NULL; fnGetConsoleWindow fn = (fnGetConsoleWindow)(GetProcAddress(hDll, "GetConsoleWindow")); if (fn != NULL) { res = fn(); } else { // error: see GetLastError() } FreeLibrary(hDll); return res; }