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?
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
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.
It makes sense in a loop
The masm documentation also says it is an effective way to reduce the size of the executable
if you can eliminate the IAT altogether, maybe
programs assembled with GoAsm are something like that, i guess
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,...