About calling Dll

Just starting out? Need help? Post your questions and find answers here.
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

About calling Dll

Post 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? :oops:
poor English...

PureBasic & Delphi & VBA
User avatar
Bisonte
Addict
Addict
Posts: 1336
Joined: Tue Oct 09, 2007 2:15 am

Re: About calling Dll

Post 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 ....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: About calling Dll

Post 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.
poor English...

PureBasic & Delphi & VBA
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: About calling Dll

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: About calling Dll

Post 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.
"Have you tried turning it off and on again ?"
Post Reply