RE: Finding HWND of the current thread

"Jon Watte" <[email protected]>
Newsgroups gmane.games.devel.windows
Message-ID <[email protected]>
May I suggest that you're not guaranteed that GetModuleHandle() returns a
pointer to your executable header, and you're not guaranteed that your
executable loads at 0x400000 ? They might have a hard time changing this
behavior for existing apps, especially because of hacky code like the posted
code, but you never know about future versions.

If you want the header, use GetModuleFileName() on the main module, and read
the header yourself. Then check whether the header is actually a "PE"
header, and just assume you're not console if it isn't. At least, that won't
CRASH when you port your code, or some new version of Windows comes out.

Cheers,

			/ h+


-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of
Jan Wassenberg
Sent: Wednesday, July 28, 2004 1:45 AM
To: [email protected]
Subject: Re: [GD-Windows] Finding HWND of the current thread


On Thu, 15 Jul 2004 14:19:49 -0400, Brian Hook <[email protected]>
wrote:
>> GetConsoleWindow
> As a library, I won't know if it's a console window or not.
You can check the Subsystem field of the PE "optional" header (always
present): if it's equal IMAGE_SUBSYSTEM_WINDOWS_CUI (3), you've got a
console app.
void* base = (void*)0x400000 (or GetModuleHandle(0))
IMAGE_NT_HEADERS* h = ImageNtHeader(base)
h->OptionalHeader.Subsystem == 3?

Disclaimer: off the top of my head and ugly to boot ;)



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.