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

Getting hinstance without WinMain

535 views
Skip to first unread message

Chris Saunders

unread,
Jan 13, 2004, 2:49:58 PM1/13/04
to
Is it possible to get the hinstance of a program
without having a WinMain function?

To put it another way, is it possible from a
regular "C" main function to get the hinstance?

Regards
Chris Saunders
chris.s...@sympatico.ca


Ali R.

unread,
Jan 13, 2004, 3:09:32 PM1/13/04
to
You don't have an hinstance if you don't have a WinMain. WinMain has
nothing to do with C vs. C++. It has to do with Windows program vs. Console
(DOS) program. And a Console program doesn't have a hInstance.

Ali R.

"Chris Saunders" <chris.s...@sympatico.ca> wrote in message
news:FZXMb.10111$881.1...@news20.bellglobal.com...

James Brown

unread,
Jan 13, 2004, 3:28:45 PM1/13/04
to
A console program certainly *does* have a hInstance. A console
program is a windows program in every right - the only difference
between a console program and a "windows" program is that for a
console program, a flag is set in the executable header which tells windows
to automatically create a console for the process when it starts, other
than that they are exactly the same.

To answer the original question, to find the hInstance at any time:

hInstance = GetModuleHandle(NULL);

Regards,
James

--
www.catch22.org.uk
Free Win32 Software, Source Code and Tutorials

"Ali R." <nos...@nospam.com> wrote in message
news:0gYMb.7814$Pb6....@newssvr22.news.prodigy.com...

Severian

unread,
Jan 13, 2004, 4:26:49 PM1/13/04
to
On Tue, 13 Jan 2004 14:49:58 -0500, "Chris Saunders"
<chris.s...@sympatico.ca> wrote:

>Is it possible to get the hinstance of a program
>without having a WinMain function?
>
>To put it another way, is it possible from a
>regular "C" main function to get the hinstance?

HINSTANCE hinst = GetModuleHandle(NULL);

On Win32 platforms I am familiar with, this will always return
0x00400000.

- Sev

Ali R.

unread,
Jan 13, 2004, 5:25:02 PM1/13/04
to
My bad.

"James Brown" <james.brown7_nosp@m_virgin.net> wrote in message
news:40045504$0$2772$cc9e...@news.dial.pipex.com...

0 new messages