Hello group;

First of all, I'm new to win32asm, and spend a fair amount of time learning stuff with Icz's tutorials (with a "fair amount of fun", too ;-) )

As I go, I try to understand what I type (doh...), so I've downloaded the Platform SDK to learn a bit about the various Win32 API functions.
I came across theses two functions: getModuleHandle, and getModuleHandleEx.

Ok, GetModuleHandle is pretty simple: it return a DWORD value, the handle of my application. Right?
Now, if you read the doc. from the Platform SDK, M$ suggest to use getModuleHandleEx.

After a bit of reading, getModuleHandleEx return a BOOL value, and the actual module handle is "returned" as the 3rd parameter of the function. How does it translates in MASM?

I know the return value of a function is most of the time in EAX; so it will contain 0 if the function fail. But that's not what I need; I want the module handle!

Thanks for any help!
Posted on 2002-07-22 23:15:36 by Workaholic
... and the actual module handle is "returned" as the 3rd parameter of the function. How does it translates in MASM?
invoke GetModuleHandleEx, ..., ..., ADDR phModule


or

invoke GetModuleHandleEx, ..., ..., OFFSET phModule
phModule must be DWORD in size.
.data?


phModule DD ?
After the API function, phModule now contains the handle(If it succeeds).

To get the pointer of a "variable" you must use ADDR or OFFSET. ph notation means pointer(p) handle(h). This is one of the notations used in the PSDK. You are not *forced* to used it. It is just there to help you quickly identify the "type" of variable used.
Posted on 2002-07-22 23:34:57 by stryker
Great, thanks for the info.

BTW, why can we use ADDR or OFFSET statement if they do the same thing ??

Isn't ADDR used with and Invoke macro and OFFSET with any other statement ?
Sorry to ask, but I'm confused a little bit.

Thanks again!
Posted on 2002-07-23 10:13:52 by Workaholic
ADDR is a macro.

MASM is smart enough to distinguish what's global and what's local "variable". Just remember these:

ADDR
- can handle local and global "variables"
- can't handle forward references
- address of a "variable" is known at runtime but if the "variables" is global this will change to OFFSET
- ADDR uses the lea instruction to get the address at runtime.

OFFSET
- can handle global "variables", can't handle locals
- can handle forward references
- address of a "variable" is known at assembly time but if the "variables" is local, MASM will flag this as an error.

In short, just use ADDR. But personally, I use ADDR for locals and OFFSET for globals.

Don't worry about forward references yet, you don't need it at this point.
Posted on 2002-07-23 11:17:11 by stryker