The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 08:40:52 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  Static Funbtion pointers
« previous next »
Pages: [1] Print
Author Topic: Static Funbtion pointers  (Read 6411 times)
Artoo
Guest


Email
Static Funbtion pointers
« on: February 20, 2005, 08:21:11 AM »

Hi,

In a C project i have a static funtion defined as:

static LRESULT CALLBACK WndProc(  HWND hwnd,        UINT uMsg,    WPARAM wParam,   LPARAM lParam )

and get the address of this function like so:

BYTE * pWndProc = (BYTE *)&WndProc;

Now trying to convert this to assembler code Ive tried this:

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.
.
.
WndProc endp

AnotherFunction proc
      MOV      EAX, WndProc
AnotherFunction endp


But this doesnt work. As it assmbles to this:

mov         eax,dword ptr [@ILT+20(_WndProc@16) (401019h)]

where the instruction at 401019h is:

jmp         WndProc (40128Ah)

So my question is, how do I get rid of this ILT (table lookup) and use the proper address of WndProc.  I guess the"static" in the C code tells the compiler to do something different. What do I have to do in my MASM code for the same effect?

Your help is much appreciated!


Logged
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: Static Funbtion pointers
« Reply #1 on: February 20, 2005, 08:53:08 AM »

You can build a different set of prototypes using the L2EXTIA.EXE tool in masm32 which will produce the address directly in code rather than the jump table at the end but there is no gain doing it.

In MASM as with any normal API based code you set the address of the WndProc in the WNDCLASSEX structure using OFFSET WndProc.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
AeroASM
Guest


Email
Re: Static Funbtion pointers
« Reply #2 on: February 20, 2005, 09:02:11 AM »

To get the address of a procedure you can use
Code:
mov eax,offset WndProc
as hutch said, because offset is like * in C.

An alternative is
Code:
lea eax,WndProc
Functionally they are equivalent, but the first one is faster.

You can use exactly the same syntax for variables as well.
Logged
Artoo
Guest


Email
Re: Static Funbtion pointers
« Reply #3 on: February 20, 2005, 09:54:46 AM »

I tired:

MOV      EAX, OFFSET ClockWndProc

but that gaves me the same address of 0x00401019, which is in the ILT.  What am I doing wrong?
Logged
Artoo
Guest


Email
Re: Static Funbtion pointers
« Reply #4 on: February 20, 2005, 10:58:57 AM »

Ok, Ive trracked it down to it being a debug, which creates the ILT ("Incremental Link Table").  In release builds no ILT is created and the real address of WndProc is used.

So my question now is must a ILT be used in my debug EXE?

Logged
AeroASM
Guest


Email
Re: Static Funbtion pointers
« Reply #5 on: February 20, 2005, 08:47:55 PM »

You are doing nothing wrong. 0x00401??? is a normal address for something in the code section, and Windows will happily receive it.

With Incremental Link, only the procedures which have been changed are recompiled and relinked. The ILT helps the linker keep track. You can disable it by adding the switch /INCREMENTAL:NO when you link.
Logged
Artoo
Guest


Email
Re: Static Funbtion pointers
« Reply #6 on: February 21, 2005, 06:45:14 AM »

Thanks everyone for your help.

The problem was with debug builds creating a ILT.  The /INCREMENTAL:NO  fixed it.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!