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?
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
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.
---
>- 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
Since they say "dynamically link", I presume they mean "using LoadLibrary
and GetProcAddress"...
Luc
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.
I'm using the January 2001 CD.
Thanks for the pointer. (Unfortunately, I cannot rely on a Win2K-only
function.)
>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
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.
...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
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?
>
>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
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.)
No, but I have mimmicked the prototypes that one finds in WINCON.H:
WINBASEAPI HWND WINAPI GetConsoleWindow(VOID);
- Vince
>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
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.
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.
|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