DLLs

Just starting out? Need help? Post your questions and find answers here.
AgentOrange
User
User
Posts: 14
Joined: Sun Oct 12, 2003 3:51 am

DLLs

Post by AgentOrange »

I got a DLL to work and function with just the following as code for dll:

Code: Select all

ProcedureDLL MyFunction()
  MessageRequester("Hello", "This is a PureBasic DLL !", 0)
EndProcedure
and this for the client exe: (basically rips from the help file)

Code: Select all

; Now the client program, which use the DLL
;
If OpenLibrary(0, "my.dll")
  CallFunction(0, "MyFunction")
  CloseLibrary(0)
Else
    MessageRequester("error", "i could not locate the dll", 0)
EndIf

End
My questions are.. as I'm looking at the DLLSample.pb file:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - DLL example file
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This example is a skeleton to build easely a DLL using PureBasic
; The dll is created in the 'Compilers' directory, under the
; 'purebasic.dll' name. An associated '.lib' is generated to use
; with LccWin32 or VisualC++.
;
;
; Rules to follow:
;   - Never write code outside a procedure, except for variables
;   or structure declaration.
;   
;   - DirectX Init routines must not be initialized in the the
;   AttachProcess() procedure
;   
;   - There is 4 procedures automatically called: AttachProcess(),
;   DetachProcess(), AttachThread() and DetachThread(). If you don't
;   need them, just remove them.
;

#TESTDLL = 0

CompilerIf #TESTDLL = 0

  ; This procedure is called once, when the program loads the library
  ; for the first time. All init stuffs can be done here (but not DirectX init)
  ;
  ProcedureDLL AttachProcess(Instance)
  EndProcedure


  ; Called when the program release (free) the DLL
  ;
  ProcedureDLL DetachProcess(Instance)
  EndProcedure


  ; Both are called when a thread in a program call or release (free) the DLL
  ;
  ProcedureDLL AttachThread(Instance)
  EndProcedure

  ProcedureDLL DetachThread(Instance)
  EndProcedure


  ; Real code start here..
  ;
  
  ProcedureDLL EasyRequester(Message$)

    MessageRequester("EasyRequester !", Message$, #MB_ICONINFORMATION)

  EndProcedure

CompilerElse

  If OpenLibrary(0, "PureBasic.dll")
    CallFunction(0, "EasyRequester", "Test")  
  EndIf
    
CompilerEndIf
; ExecutableFormat=Shared Dll
; Executable=C:\Programmation\Projets\PureBasic Visual Designer\Dll.Exe
; DisableDebugger
; EOF
question1. Does anyone have a sample of how these other four Procedures work?

question2. Do the last for lines do anything, or are they just regular comments?

..
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I'm only going on the comments here.
; This procedure is called once, when the program loads the library
; for the first time. All init stuffs can be done here (but not DirectX init)
;
ProcedureDLL AttachProcess(Instance)
EndProcedure
Put any initialization stuff in this procedure - anything you want done when someone loads up your library..
; Called when the program release (free) the DLL
;
ProcedureDLL DetachProcess(Instance)
EndProcedure
Looks like any clean up code would go here - it gets executed when someone closes/frees the DLL..
; Both are called when a thread in a program call or release (free) the DLL
;
ProcedureDLL AttachThread(Instance)
EndProcedure

ProcedureDLL DetachThread(Instance)
EndProcedure
Looks like these get executed in addition to the others when you open (Attach) or close (Detach) the DLL..

Looks like these are only provided so that you can do things when a user opens or closes your library. If you don't need to do anything at those times then just don't include these procedures..

Again, I'm only going by the comments in there :-)

I think those last few lines have some meaning but I'll be darned if I know what that meaning is!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Re: DLLs

Post by RJP Computing »

AgentOrange wrote:question2. Do the last for lines do anything, or are they just regular comments?
Those are comments, but they are used by the PureBasic editor to keep the settings correct for the compiler on a PER file basis. Basicaly so that you don't have to enter the type of program and the location you want the *.exe/*.dll to be when done compiling.

Hope this clears things up.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
AgentOrange
User
User
Posts: 14
Joined: Sun Oct 12, 2003 3:51 am

Re: DLLs

Post by AgentOrange »

RJP Computing wrote:Those are comments, but they are used by the PureBasic editor to keep the settings correct for the compiler on a PER file basis. Basicaly so that you don't have to enter the type of program and the location you want the *.exe/*.dll to be when done compiling.

Hope this clears things up.
Thanks all for the replies. On question2.. so they are NOT just comments, they are being read by the compiler and setting the appropriate flags for compile time?

ao
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Close they are being read by the PureBasic Editor and setting the parameters it is going to send to the compiler. Just for clarification the editor and the compiler are two separate things. The Editor is a nice shell around the compiler.

Hope that makes more sense.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
AgentOrange
User
User
Posts: 14
Joined: Sun Oct 12, 2003 3:51 am

..

Post by AgentOrange »

RJP Computing wrote:Close they are being read by the PureBasic Editor and setting the parameters it is going to send to the compiler. Just for clarification the editor and the compiler are two separate things. The Editor is a nice shell around the compiler.

Hope that makes more sense.
Thanks.

10-4 on the editor reading, and sending that to the compiler..

Do you know off hand if there is anything in the help file about what were are discussing?

ao
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Nope I don't believe that is covered in the help file.

Unless you are talking about the parameters that you can send the compiler. That is in the help file. Under "Using the command line Compiler"

Hope this helps. :D
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
User avatar
waffle
Enthusiast
Enthusiast
Posts: 129
Joined: Mon May 12, 2003 1:34 pm
Location: USA
Contact:

Post by waffle »

ProcedureDLL AttachProcess(Instance)
EndProcedure

ProcedureDLL DetachProcess(Instance)
EndProcedure

If your DLL needs memory buffers, this is where you would reserve memory for them. Also good for setting up your linkedlists.

example:
#Memory = 1
#Size = 1000
global *Buffer

ProcedureDLL AttachProcess(Instance)
*Buffer=AllocateMemory(#Memory, Size, 0)
EndProcedure

ProcedureDLL DetachProcess(Instance)
FreeMemory(#Memory)
*Buffer=0
EndProcedure
AgentOrange
User
User
Posts: 14
Joined: Sun Oct 12, 2003 3:51 am

..

Post by AgentOrange »

RJP Computing wrote:Nope I don't believe that is covered in the help file.

Unless you are talking about the parameters that you can send the compiler. That is in the help file. Under "Using the command line Compiler"

Hope this helps. :D
Hey guys, that's great. Thanks for all the help!!

ao
Post Reply