Easy way to use a DLL (v4)

Everything else that doesn't fall into one of the other PB categories.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Easy way to use a DLL (v4)

Post by Dare2 »

Take this code and save it somewhere as PureToLib.pb

Code: Select all

Global inst.l
ProcedureDLL AttachProcess(Instance)
  inst = Instance
EndProcedure

ProcedureDLL GetDLLinstance()
  ProcedureReturn inst
EndProcedure
ProcedureDLL Get27()
  ProcedureReturn 27
EndProcedure
ProcedureDLL alert(t.s,m.s,f = 0)
  MessageRequester(t,m,f)
EndProcedure
Compile it as a DLL (PureToLib.dll)
Now run this code (change the path!):

Code: Select all

Import "Path\To\Where\You\compiled\the\above\PureToLib.lib"
  GetInstance.l() As "_GetDLLinstance@0"
  GetThreeNines.l() As "_Get27@0"
  Mbox.l(ptrT.l,ptrM.l,f.l) As "_alert@12"
EndImport 

Debug GetInstance()
Debug GetThreeNines()
t.s="Title"
m.s="Message"
f=0
mBox(@t,@m,f)
mBox(@"WoooHooo",@"Love this!",#MB_ICONEXCLAMATION)
Any thoughts?

An easy way to use dlls!


Edit: Don't change or remove the DLL!

Edit again: Changed the title (tailbite -v- DLL) which was for another thread! Sorry!
@}--`--,-- A rose by any other name ..
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The lib file generated by the Compiler is only a so called import library.
This means its a static lib that only calls the Dll functions (this is used in C a lot)

So your program still requires the Dll.

Edit: editing while i am typing a response is mean :twisted:
quidquid Latine dictum sit altum videtur
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Posting whilst I'm editing is mean!

:)

Sorry. I had two posts going and pasted into the wrong one!
@}--`--,-- A rose by any other name ..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

So the DLL has to be there at runtime then? Am I reading this right?
Last edited by netmaestro on Tue Feb 21, 2006 3:04 pm, edited 2 times in total.
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

It's the static way to load a DLL
when the application don't find the DLL, gives a error by windows.

for some things it's better to use dynamic call
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
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

yes, i found this feature very appealing, also remember that you can do the same for static libs, no longer do you need to write wrappers. :)
Post Reply