Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem getting console window handle

71 views
Skip to first unread message

Bruce Varley

unread,
Apr 21, 2013, 3:21:02 AM4/21/13
to
Need to get the window handle for a Win32 console app. According to a few
websites, the following should work:

#include <windows.h>

HWND hConsole ;

int main()
{
hConsole = GetConsoleWindow() ;
.......
}

But the compile reports an error:
error C2065: 'GetConsoleWindow' : undeclared identifier

The project link settings do include kernel32.lib, as instructed.

Any assistance much appreciated.


David Lowndes

unread,
Apr 21, 2013, 4:39:52 AM4/21/13
to
>But the compile reports an error:
>error C2065: 'GetConsoleWindow' : undeclared identifier

Check the remarks section of the documentation:
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms683175(v=vs.85).aspx

You will of course need to be using tools that post-date Windows 2000
to have the header definition & lib.

Dave

Geoff

unread,
Apr 21, 2013, 12:40:32 PM4/21/13
to
On Sun, 21 Apr 2013 15:21:02 +0800, "Bruce Varley" <b...@NoSpam.com>
wrote:
This is a compiler error, not a linker error, so don't fret about the
libs just yet, you haven't gotten that far.

You can use the Visual Studio IDE to jump to the definition of these
constants or you can add this to your source to verify David's
suggestion:

#ifndef _WIN32_WINNT
#error _WIN32_WINNT not defined
#endif

#ifndef _WIN32
#error _WIN32 not defined
#endif

#ifndef _CONSOLE
#error _CONSOLE not defined
#endif

These will stop compiliation if your project is incorrectly targeted.
0 new messages