Hello, I have a DLL that exprots some functions. I need to call then from an app. I have to pass some parameter to the functions. I'm loading the dll using the LoadLibrary API. How can I call the function by typedef ing a pointer to a function like in C++. typedef DWORD (*fptr)(DWORD one, DWORD two); fptr func; fptr = GetProcAddress(hMod, "MyFunc"); And I have one more question. How do I get hold of the address of a variable. i could do mov eax, offset var. this works only in the case of global variable. in case of local i cannot use addr, cause it shows me an error. Pls help Clark
Posted on 2001-06-25 07:15:00 by Superman_San
For calling functions from dll check Iczelion's tutorial no 17 (http://www.win32asm.com/tut17.html). Second problem: SomeFunction PROC LOCAL someVar :DWORD LOCAL dwAddress :DWORD LEA ECX, someVar MOV dwAddress, ECX ;now, dwAddress contains poiter to someVar RET SomeFunction ENDP
Posted on 2001-06-25 07:31:00 by gedik
the following works:

FUNCP2  typedef proto a1:dword,a2:dword
PFUNCP2 typedef ptr FUNCP2


dwProcptr PFUNCP2 0 ;<- here a real proc address is needed  

    invoke dwProcptr,1,2

But may be there exists a simpler solution. I would be interested to know it. japheth
Posted on 2001-06-25 07:41:00 by japheth
The second solution is fine. But in the tutorial there is no typedef ptr. Hez getting the function address and issuing a call. I want to know how I can use the invoke macro to call the function. Clark
Posted on 2001-06-25 07:50:00 by Superman_San
Nice one, Japheth, but will it still work if the DLL is not at its preferred load address (i.e. its ImageBase according to the PE file)? That is, will the proc address in the asm source still be valid? If you make your own symbol library to fit the DLL, you can use includelib, just as we do with API symbol libraries. Or you can wait for me to finish my own linker, which will do away with symbol libraries altogether :D (Edit) The LCC-WIN32 package contains a gadget for making import libraries: IMPLIB.EXE. Usage is implib my.dll and out pops my.lib, a symbol library corresponding to my.dll. The export table in my.dll must be in a section ".edata" or ".rdata", and that will be true if the dll was built with MASM,Microsoft C, or LCC-WIN32. This message was edited by Larry Hammick, on 6/25/2001 9:02:09 PM
Posted on 2001-06-25 14:12:00 by Larry Hammick
Hello Larry, I think the code above should always work, no matter where the dll is loaded. For there are 2 real life situations. 1. get a proc address from GetProcAddress FUNCP2 typedef proto a1:dword,a2:dword PFUNCP2 typedef ptr FUNCP2 .data dwProcptr PFUNCP2 0 ;<- here a real proc address is needed .code invoke GetProcAddress,xxxx mov dwProcptr,eax invoke dwProcptr,1,2 2. use a symbol from the IAT FUNCP4 typedef proto a1:dword,a2:dword,a3:dword,a4:dword PFUNCP4 typedef ptr FUNCP4 .data externdef _imp__MessageBoxA@16:PFUNCP4 .code invoke _imp__MessageBoxA@16,0,addr str,0,0 japheth
Posted on 2001-06-26 03:34:00 by japheth