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

GetConsoleWindow()

362 views
Skip to first unread message

Kenneth Brody

unread,
Jul 17, 2001, 10:55:59 PM7/17/01
to
Okay...

Q124103 says that in order to get the HWND of a console window, you need
to go through a bunch of hoops.

Part of the MSDN documents a GetConsoleWindow() function which does exactly
that -- returns the HWND. However, it does not list any of the details that
are included with the rest of the Windows API, such as which version of
Windows is required, which header file it's declared in, and which .lib you
need. Nor does it say "prelimiary information", as much of the new stuff
is labelled with. Also, I checked *.h in the MSVC and Watcom directories
and it's not declared in any of them, and the linker can't find it either.

Is this a function that just doesn't exist, yet was documented anyway? Or
does it just require Win2K or WinMe? Or perhaps it's just not included in
the header files, but it really exists somewhere?

--

+---------+----------------------------------+-----------------------------+
| Kenneth | kenb...@bestweb.net | "The opinions expressed |
| J. | | herein are not necessarily |
| Brody | http://www.bestweb.net/~kenbrody | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+
GCS (ver 3.12) d- s+++: a C++$(+++) ULAVHSC^++++$ P+>+++ L+(++) E-(---)
W++ N+ o+ K(---) w@ M@ V- PS++(+) PE@ Y+ PGP-(+) t+ R@ tv+() b+
DI+(++++) D---() G e* h---- r+++ y?

Luc Kumps

unread,
Jul 18, 2001, 2:11:04 AM7/18/01
to

"Kenneth Brody" <kenb...@bestweb.net> wrote in message
news:3B54FB7D...@bestweb.net...

> Okay...
>
> Q124103 says that in order to get the HWND of a console window, you need
> to go through a bunch of hoops.
>
> Part of the MSDN documents a GetConsoleWindow() function which does
exactly
> that -- returns the HWND. However, it does not list any of the details
that
> are included with the rest of the Windows API, such as which version of
> Windows is required, which header file it's declared in, and which .lib
you
> need. Nor does it say "prelimiary information", as much of the new stuff
> is labelled with. Also, I checked *.h in the MSVC and Watcom directories
> and it's not declared in any of them, and the linker can't find it either.
>
> Is this a function that just doesn't exist, yet was documented anyway? Or
> does it just require Win2K or WinMe? Or perhaps it's just not included in
> the header files, but it really exists somewhere?

You must be using an old version of the MSDN CD-ROM, because my CD-ROM tells
us everything we need to know:

- Win2000 only
- will be defined in wincon.h in the future.
"Although this function was implemented in Windows 2000, it was not included
in the version of Wincon.h that was included with the Platform SDK for
Windows 2000. To use this function on Windows 2000, use the prototype
included in this documentation, and dynamically link to the function in
Kernel32.dll."

For the online MSDN doc, see
http://msdn.microsoft.com/library/en-us/fileio/hh/winbase/conchar_3eif.asp


Luc

Alex Blekhman

unread,
Jul 18, 2001, 3:13:23 AM7/18/01
to
"Kenneth Brody" <kenb...@bestweb.net> wrote in message
news:3B54FB7D...@bestweb.net...
> Okay...
>
> Q124103 says that in order to get the HWND of a console window, you
need
> to go through a bunch of hoops.
>
> Part of the MSDN documents a GetConsoleWindow() function which does
exactly
> that -- returns the HWND. However, it does not list any of the
details that
> are included with the rest of the Windows API, such as which version
of
> Windows is required, which header file it's declared in, and which
.lib you
> need. Nor does it say "prelimiary information", as much of the new
stuff
> is labelled with. Also, I checked *.h in the MSVC and Watcom
directories
> and it's not declared in any of them, and the linker can't find it
either.
>
> Is this a function that just doesn't exist, yet was documented
anyway? Or
> does it just require Win2K or WinMe? Or perhaps it's just not
included in
> the header files, but it really exists somewhere?
>

Yes, this function was a mystery for a long time already. Until in
April 2001 MSDN appeared following note:
---
Note: Although this function was implemented in Windows 2000, it was


not included in the version of Wincon.h that was included with the
Platform SDK for Windows 2000. To use this function on Windows 2000,
use the prototype included in this documentation, and dynamically link
to the function in Kernel32.dll.

---

Vincent Fatica

unread,
Jul 18, 2001, 7:38:41 AM7/18/01
to
On Wed, 18 Jul 2001 06:11:04 GMT, "Luc Kumps" <NOkum...@pandora.be>
wrote:

>- Win2000 only
>- will be defined in wincon.h in the future.
>"Although this function was implemented in Windows 2000, it was not included
>in the version of Wincon.h that was included with the Platform SDK for
>Windows 2000. To use this function on Windows 2000, use the prototype
>included in this documentation, and dynamically link to the function in
>Kernel32.dll."

But what exactly do they mean? The function in exported by KERNEL32.DLL,
and it's specified in VC6's KERNEL32.LIB (see below) but not in the PSDK
version of KERNEL32.LIB. Using the prototype given in the article quoted,
the function is not found at link time. THe following is from a DUMPBIN of
the VC6 KERNEL32.DLL:

Version : 0
Machine : 14C (i386)
TimeDateStamp: 3501AD2C Sat Mar 07 15:25:16 1998
SizeOfData : 00000021
DLL name : KERNEL32.dll
Symbol name : _GetConsoleWindow@0
Type : code
Name type : undecorate
Hint : 241
Name : GetConsoleWindow

- Vince

Luc Kumps

unread,
Jul 18, 2001, 9:23:43 AM7/18/01
to

"Vincent Fatica" <vefa...@syr.edu> wrote in message
news:3b557588$1@localhost...

Since they say "dynamically link", I presume they mean "using LoadLibrary
and GetProcAddress"...

Luc

Kenneth Brody

unread,
Jul 18, 2001, 11:36:24 AM7/18/01
to
Alex Blekhman wrote:
>
> "Kenneth Brody" <kenb...@bestweb.net> wrote in message
> news:3B54FB7D...@bestweb.net...
[...]

> > Part of the MSDN documents a GetConsoleWindow() function which does
[...]

> Yes, this function was a mystery for a long time already. Until in
> April 2001 MSDN appeared following note:
> ---
> Note: Although this function was implemented in Windows 2000, it was
> not included in the version of Wincon.h that was included with the
> Platform SDK for Windows 2000. To use this function on Windows 2000,
> use the prototype included in this documentation, and dynamically link
> to the function in Kernel32.dll.
> ---

Here is the entire description of GetConsoleWindow() on the Jan.2001 CD:

=====

Platform SDK: Files and I/O

GetConsoleWindow

The GetConsoleWindow function retrieves the window handle used by the console
associated with the calling process.

HWND GetConsoleWindow (VOID);

Parameters

None.

Return Values

The return value is a handle to the window used by the console associated
with the calling process or NULL if there is no such associated console.

See Also
Consoles and Character Support Overview, Console Functions

Built on Thursday, October 12, 2000

=====

In any case, if it's Win2K only, it doesn't do me any good.

Kenneth Brody

unread,
Jul 18, 2001, 11:36:26 AM7/18/01
to
Luc Kumps wrote:
>
> "Kenneth Brody" <kenb...@bestweb.net> wrote in message
[...]

> > Part of the MSDN documents a GetConsoleWindow() function which does
[...]

> You must be using an old version of the MSDN CD-ROM, because my CD-ROM tells
> us everything we need to know:
>
> - Win2000 only
> - will be defined in wincon.h in the future.
> "Although this function was implemented in Windows 2000, it was not included
> in the version of Wincon.h that was included with the Platform SDK for
> Windows 2000. To use this function on Windows 2000, use the prototype
> included in this documentation, and dynamically link to the function in
> Kernel32.dll."
>
> For the online MSDN doc, see
> http://msdn.microsoft.com/library/en-us/fileio/hh/winbase/conchar_3eif.asp

I'm using the January 2001 CD.

Thanks for the pointer. (Unfortunately, I cannot rely on a Win2K-only
function.)

Vincent Fatica

unread,
Jul 18, 2001, 9:49:58 PM7/18/01
to
On Wed, 18 Jul 2001 13:23:43 GMT, "Luc Kumps" <NOkum...@pandora.be>
wrote:

>Since they say "dynamically link", I presume they mean "using LoadLibrary
>and GetProcAddress"...

Yes, that works. But I wonder ...

KERNEL32.DLL is, by default, dynamically linked to apps. If KERNEL32.DLL
exports GetConsoleWindow(), and KERNEL32.LIB mentions it (contains a "stub"
(?) for it), and I prototype it correctly, why doesn't the linker find it?

Thanks.

- Vince

Tonu Aas

unread,
Jul 19, 2001, 4:17:09 AM7/19/01
to
> HWND GetConsoleWindow (VOID);

> In any case, if it's Win2K only, it doesn't do me any good.

O.k. use that (works under W95,98,Nt,2000)
-------------
char marking_title[11];
sprintf(marking_title, "_%08X_", GetCurrentThreadId());
SetConsoleTitle(marking_title);
Sleep(10); // This must be here !!!
hwnd_console = FindWindow(NULL, marking_title);
SetConsoleTitle("");
--------------

Tõnu.


Jugoslav Dujic

unread,
Jul 19, 2001, 5:48:45 AM7/19/01
to

"Vincent Fatica" <vefa...@syr.edu> wrote in message
news:3b563d0c$1@localhost...

...but Kernel32.lib doesn't contain a stub for it. My version of lib
dates from 1998, so I'm not positive about newer versions, but my W2K
Kernel does contain GetConsoleWindow but Kernel32.lib doesn't. Try
search in Explorer in Program Files/.../Lib | *.lib | (Containing text
"GetConsoleWindow")

Jugoslav


Vincent Fatica

unread,
Jul 19, 2001, 7:38:47 AM7/19/01
to
My KERNEL32.LIB (1998/05/13) does contain it. Explorer says so and
DUMPBIN.EXE says so:

Dump of file KERNEL32.LIB

[snip]

Version : 0
Machine : 14C (i386)
TimeDateStamp: 3501AD2C Sat Mar 07 15:25:16 1998
SizeOfData : 00000021
DLL name : KERNEL32.dll
Symbol name : _GetConsoleWindow@0
Type : code
Name type : undecorate
Hint : 241
Name : GetConsoleWindow

So I still wonder why the linker doesn't find it.

- Vince

On Thu, 19 Jul 2001 11:48:45 +0200, "Jugoslav Dujic" <jdu...@yahoo.com>
wrote:

>
>"Vincent Fatica" <vefa...@syr.edu> wrote in message
>news:3b563d0c$1@localhost...
>| On Wed, 18 Jul 2001 13:23:43 GMT, "Luc Kumps" <NOkum...@pandora.be>
>| wrote:
>| Yes, that works. But I wonder ...
>|
>| KERNEL32.DLL is, by default, dynamically linked to apps. If KERNEL32.DLL
>| exports GetConsoleWindow(), and KERNEL32.LIB mentions it (contains a "stub"
>| (?) for it), and I prototype it correctly, why doesn't the linker find it?
>

Frank Ostrowski

unread,
Jul 19, 2001, 11:32:36 AM7/19/01
to
Vincent Fatica <vefa...@syr.edu> wrote:

>My KERNEL32.LIB (1998/05/13) does contain it. Explorer says so and
>DUMPBIN.EXE says so:

> Symbol name : _GetConsoleWindow@0


>So I still wonder why the linker doesn't find it.

How is your prototype for GetConsoleWindow(). Do you use extern "C"
(assuming C++)?

Frank

Kenneth Brody

unread,
Jul 19, 2001, 1:05:52 PM7/19/01
to

That's similar to the code given in the MSDN. I was just hoping to have
a true API call rather than this nasty kludge.

(Though you'd probably want to use GetConsoleTitle() to save and restore
the title, rather than set it to blank at the end.)

Vincent Fatica

unread,
Jul 19, 2001, 3:57:30 PM7/19/01
to

No, but I have mimmicked the prototypes that one finds in WINCON.H:

WINBASEAPI HWND WINAPI GetConsoleWindow(VOID);

- Vince

Vincent Fatica

unread,
Jul 19, 2001, 4:16:35 PM7/19/01
to
On Thu, 19 Jul 2001 17:32:36 +0200, Frank Ostrowski <fr-...@web.de> wrote:

>How is your prototype for GetConsoleWindow(). Do you use extern "C"
>(assuming C++)?

OK (thanks), this works (in a .CPP):

extern "C" {
WINBASEAPI HWND WINAPI GetConsoleWindow(VOID);
}

**BUT** I had to make sure that the VC6 KERNEL32.LIB was the library found
(instead of the PSDK KERNEL32.LIB) by renaming (momentarily) the PSDK one.

- Vince

Kenneth Brody

unread,
Jul 19, 2001, 6:52:33 PM7/19/01
to

There's your problem.

Check the top of wincon.h, and you'll find:

#ifdef __cplusplus
extern "C" {
#endif

This makes all definitions in wincon.h extern "C". By duplicating the
single line, you have not made it a "C" declaration.

Tonu Aas

unread,
Jul 20, 2001, 5:41:03 AM7/20/01
to
> > > HWND GetConsoleWindow (VOID);
> > > In any case, if it's Win2K only, it doesn't do me any good.
> >
> > O.k. use that (works under W95,98,Nt,2000)
> That's similar to the code given in the MSDN. I was just hoping to have
> a true API call rather than this nasty kludge.

I think you cant do it portable.
These windowses are very unportable specially for consoles.
Under each family there are some tricks and bugs and MS adds new ones
for each new windows and doesnt fix any.

> (Though you'd probably want to use GetConsoleTitle() to save and restore
> the title, rather than set it to blank at the end.)

Maybe.


Vincent Fatica

unread,
Jun 27, 2010, 5:33:09 PM6/27/10
to
On Wed, 18 Jul 2001 02:55:59 GMT, Kenneth Brody <kenb...@bestweb.net>
wrote:

|Part of the MSDN documents a GetConsoleWindow() function which does exactly
|that -- returns the HWND. However, it does not list any of the details that
|are included with the rest of the Windows API, such as which version of
|Windows is required, which header file it's declared in, and which .lib you
|need. Nor does it say "prelimiary information", as much of the new stuff
|is labelled with. Also, I checked *.h in the MSVC and Watcom directories
|and it's not declared in any of them, and the linker can't find it either.

It requires Windows 2000 or later. Read about it here:

http://msdn.microsoft.com/en-us/library/ms683175%28VS.85%29.aspx

WITH MSVC9, it's declaration is inside #if(_WIN32_WINNT >= 0x0500)
--
- Vince

0 new messages