Page 1 of 1

DLLs

Posted: Tue Oct 14, 2003 3:07 am
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?

..

Posted: Tue Oct 14, 2003 4:44 am
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!

Re: DLLs

Posted: Tue Oct 14, 2003 6:00 am
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.

Re: DLLs

Posted: Tue Oct 14, 2003 6:26 am
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

Posted: Tue Oct 14, 2003 6:37 am
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.

..

Posted: Tue Oct 14, 2003 6:43 am
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

Posted: Tue Oct 14, 2003 7:18 am
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

Posted: Tue Oct 14, 2003 7:35 am
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

..

Posted: Tue Oct 14, 2003 4:11 pm
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