Is this handle the same as the handle to the current instance in WinMain? If so, why not just get the handle off the stack (in a Win program) when WinMain is called? I have a couple of small test programs where I do this and everything works fine but maybe I'm missing something?
Posted on 2003-03-09 11:46:58 by drhowarddrfine
Hi,
these values are only the same,if you pass the correct handle as a parameter to winmain(i think)... but this still means that you have to call GetModuleHandle before calling WinMain......i dont see any problem getting the handle off the stack. well hope that helps.
Posted on 2003-03-09 13:00:22 by keyoke

On Win32 GetModuleHandle() will return the base address of your process, which usually is $00400000.
WinMain depends on the implementation.. i.e. the entrypoint in a raw, pure asm program, is not WinMain and doesn't contain any HINSTANCE. It's up to you (or to the startup code you will use) to get the HINSTANCE and command line parameters. AFAIK hutch's MASM package offers such a startup code, but it's always part of your application (whether implicitly added or not). On the stack you will find the return address for ExitThread(), but not much more than that.

In any case, a call to GetModuleHandle is very fast and short, and thus should not pose any problem.
If you have an extreme need to save bytes (e.g. 1 KB intros), then you may "hack it" and use a hardcoded value, the same that you use as base address in your linker (usually $00400000).
Posted on 2003-03-09 13:07:50 by Maverick
Yes, I'm talking about asm in a Win program that does use WinMain. Thanks guys, it's what I thought.
Posted on 2003-03-09 13:15:26 by drhowarddrfine