Bypassing CallFunction limitations

Everything else that doesn't fall into one of the other PB categories.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Bypassing CallFunction limitations

Post by jack »

I was asked how to pass double precision variables to a dll by value, it seems that the person was exeeding the parameter limit to callFunction, which at present is 20.
I came up with this, have not tested it since i don't have a dll to test with, let me know what you think, especially if there are errors.

Code: Select all

DefType.double x,y
;the equivalent of:
;OpenLibrary(1, "C:\Program Files\PureBasic\PureLibraries\UserLibraries\myDll.dll")
;  CallFunction(1,"MYDLLFUNCTION",x,y)

ModuleHandle.l=LoadLibrary_("C:\Program Files\PureBasic\PureLibraries\UserLibraries\myDll.dll")
FunctionPointer.l=GetProcAddress_(ModuleHandle,"MYDLLFUNCTION")
! lea    eax,[v_y]
! push   dword [eax+4] ;y\b
! push   dword [eax]   ;y\a
! lea    eax,[v_x]
! push   dword [eax+4] ;x\b
! push   dword [eax]   ;x\a
! call dword [v_FunctionPointer]
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

confirmed, it works :)
btw, example how to push the address of a string variable, use variable.s not variable$

Code: Select all

! push dword [v_variable]
and of course, functions that return a long is stored in eax.
now if only i could figure out how to do it in a procedure.
Post Reply