Page 1 of 1
About calling Dll
Posted: Wed Sep 12, 2012 1:23 pm
by leonhardt
In Delphi or C you can call functions in Dlls in two ways:dynamic or static way,for example,
static way(Delphi):
//declare
procedure Foo(s:string); external 'abc.dll' ;
//use
Foo('fff')...
dynamic way:
type TFunc=procedure(s:string) ;
var p:TFunc;
h:=LoadLibraryA('abc.dll')
p:=GetProcAddress(h,'Foo')
p('sdf');...
while in PB,I can use
OpenLibrary and GetFunction...I think this is dynamic way.
how can I use the static way?

Re: About calling Dll
Posted: Wed Sep 12, 2012 1:41 pm
by Bisonte
Prototypes ?
Code: Select all
Prototype pExternalCall(Param1, Param2)
If OpenLibrary(0, "some.dll")
Global MyExCall.pExternalCall = GetFunction(0, "FunctionName")
CloseLibrary(0)
EndIf
Var = MyExCall(1,2)
I think ....
Re: About calling Dll
Posted: Wed Sep 12, 2012 1:48 pm
by leonhardt
Bisonte wrote:Prototypes ?
Code: Select all
Prototype pExternalCall(Param1, Param2)
If OpenLibrary(0, "some.dll")
Global MyExCall.pExternalCall = GetFunction(0, "FunctionName")
CloseLibrary(0)
EndIf
Var = MyExCall(1,2)
I think ....
well,that's a dynamic way, you must "open" a library,.(just like "LoadLibrary"),if your dll does not exist, nothing wrong will happen,but you will see a error dialog if you use the static way.
Re: About calling Dll
Posted: Wed Sep 12, 2012 2:06 pm
by ts-soft
For static binding a dll you have to import the lib of the dll!
If you don't have the lib, you can create it with polib.exe.
Re: About calling Dll
Posted: Wed Sep 12, 2012 2:22 pm
by luis
Keep in mind with the "static" linking using a import library your program will simply quit if the dll is missing, at least on PB since it does not perform a delayed loading (AFAIK).
Linking it at runtime you can check if the dll exists.