Hello All, I have a DLL I'm attempting to use, I'm able to load and call functions in the DLL, but don't know how to pass parameters along with the function calls.
Also need to capture the return results.
Below is an example of what needs to be sent and how far I got.

==========================================
Function Name in DLL = 'erase'
String to be sent = "1234567890987654321"
Return Value of all function calls are either '0' or '-1'
==========================================

.data
LibName db "library.dll",0
KeyStr db "1234567890987654321",0

.data?
hLib
lpProc

.code
invoke LoadLibrary, addr LibName
.if eax==NULL
GOTO ERROR
.else
mov hLib ,eax
invoke GetProcAddress, hLib, addr FunctionName
mov lpProc ,eax
call ;How would KeyStr be added to this call
...
...
.endif

Finally, some of the functions in the DLL require an empty buffer to be passed with the function call, and any result value is placed in this buffer on it's return.
Not sure how this would be done in asm, but in 'C' I do it like this.

int main()
{
char szBlock[40];

if (getBlock(szBlock, 40) ==0)
Success;
else
Fail;
return 0;
}

In this example, what would be the correct way to define this buffer type, and send it with the call getBlock, along with the parameter 40 (40 is length of the return result in the buffer)

Any help much appreciated..!

Regards
Enforcer
Posted on 2001-10-01 15:06:54 by Enforcer
When passing strings to functions you push a pointer to the string on the stack. If you use invoke to call the function then addr KeyStr will pass the pointer for you.
Posted on 2001-10-01 15:18:17 by Eóin


.data
LibName db "library.dll", 0
KeyStr db "1234567890987654321", 0
ProcName db "erase", 0
.data?
lResult dd ?

.code

invoke LoadLibrary, addr LibName

.if eax != 0
push eax ;---------we push the eax-------------------+
invoke GetProcAddress, eax, addr ProcName ; |
push offset KeyStr ; push address of string to stack |
call eax ; call function |
mov lResult, eax ; save return value |
call FreeLibrary ; <-----for the FreeLibrary call----+
.else

; do some stuff

.endif
[...]





.data
LibName db "library.dll", 0
ProcName db "getBlock", 0
.data?
lResult dd ?
Buffer db 40 dup (?) ; dimension empty buffer

.code

invoke LoadLibrary, addr LibName

.if eax != 0
push eax ;---------we push the eax-------------------+
invoke GetProcAddress, eax, addr ProcName ; |
push 40 ; push size of buffer |
push offset Buffer ; push address of buffer |
call eax ; call function |
mov lResult, eax ; save return value |
call FreeLibrary ; <-----for the FreeLibrary call----+
.else

; do some stuff

.endif

invoke MessageBox, 0, addr Buffer, 0, 0
[...]

Hope this helps!

bAZiK
Posted on 2001-10-01 16:49:30 by bazik
Thanks for your quick responce guy's.
baZiK, that bit of code you re-engineered was excatly what I was looking for, and it works well, thanks alot.

Regards
Enforcer
Posted on 2001-10-01 23:08:30 by Enforcer