News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Static Funbtion pointers

Started by Artoo, February 20, 2005, 08:21:11 AM

Previous topic - Next topic

Artoo

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!



hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

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

An alternative is lea eax,WndProcFunctionally they are equivalent, but the first one is faster.

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

Artoo

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?

Artoo

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?


AeroASM

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.

Artoo

Thanks everyone for your help.

The problem was with debug builds creating a ILT.  The /INCREMENTAL:NO  fixed it.