Page 1 of 1

Easy way to use a DLL (v4)

Posted: Thu Feb 09, 2006 1:36 am
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!

Posted: Thu Feb 09, 2006 1:42 am
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:

Posted: Thu Feb 09, 2006 1:46 am
by Dare2
Posting whilst I'm editing is mean!

:)

Sorry. I had two posts going and pasted into the wrong one!

Posted: Thu Feb 09, 2006 2:02 am
by netmaestro
So the DLL has to be there at runtime then? Am I reading this right?

Posted: Thu Feb 09, 2006 2:17 am
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

Posted: Thu Feb 09, 2006 2:53 am
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. :)