News:

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

externdef question

Started by zemtex, July 23, 2011, 02:13:30 AM

Previous topic - Next topic

zemtex

It's been awhile since I've played with assembly and I have a question about externdef

externdef _imp__CreateWindowExA@48:PTR pr12

(I plucked it out from one of hutch's samples)

I am familiar with public, extern, externdef and proto, but I can NOT remember what "pr1" and "pr2" .... "pr12" means. I think it is parameternumber so that the linker can effectively calculate the start address of the function, maybe not?
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

that's called a "declspec" declaration
the prN is the number of dword parameters the function requires

if you use a regular invoke, the assembler generates a relative call into the IAT
in the IAT is an indirect JMP dword ptr [address]
the address is a lookup into another table that has the address of the actual code
that is 3 steps of reference

by using declspec calls, you eliminate 1 of the 3 reference steps
the assembler generates a CALL dword ptr [address]
again, the address is a lookup into another table that has the address of the actual code

if you look at this thread...
http://www.masm32.com/board/index.php?topic=17073.0
you will see that i wrote a routine that removes another step
it works best on regular invoke's because there is no NOP required
CALL indirect is a 2 byte instruction (plus a 4 byte operand)
i replace one of the 2 bytes with a NOP

hutch--

zemtex,

Its just a macro for the argument count, it saved loading the data structures in the assembler with a mountain of argument prototype data when all you needed was the arg count.

The main gain with using that form of prototyping is it does a direct address call rather than branching to the lookup table at the end of the PE file. In most instances it does not matter but in some context you get a slightly faster function call from it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zemtex

It makes sense in a loop

The masm documentation also says it is an effective way to reduce the size of the executable
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

if you can eliminate the IAT altogether, maybe
programs assembled with GoAsm are something like that, i guess

sinsi

It's also a good way if you call the same function a lot e.g. CreateWindowEx in the WM_CREATE code.
Prototype it, use assume esi:ptr whatever then you can use invoke esi,...
Light travels faster than sound, that's why some people seem bright until you hear them.