Page 1 of 1

DLL example?

Posted: Tue Apr 09, 2024 11:20 am
by charvista
Hello,
I am trying to understand the DLL concept in PureBasic for the first time.
The examples provided in the help file are not runable, or I am missing something.
The below code can be found in the help file, tab 'Index', "Declare DLL":

Code: Select all

  ProcedureDLL MyFunction()
    MessageRequester("Hello", "This is a PureBasic DLL !", 0)
  EndProcedure
    
  ; Now the client program, which use the DLL
  ;
  If OpenLibrary(0, "PureBasic.dll")
    CallFunction(0, "MyFunction")
    CloseLibrary(0)
  EndIf

Simply Pressing F5 on this, does nothing visible.
As it is not very well explained, I think I must save the block procedureDLL - EndProcedure only as PureBasic.dll... How do we save that as a DLL??? No explanation there. If I'm doing that in the PB editor, I'm selecting File/Save As, then selecting "All files (*.*)" and write "PureBasic.dll" in the File name field, then press the Save button. The editor screen then becomes pale yellow (instead of my black background), and the .dll file is an Ascii file, prefixing with  (Hex EF BB BF 0D 0A).
And the block "; Now the client program...." as a standard .pb
Running the standard .pb has only the effect to show a warning message that says that PureBasic.dll is wrong or contains an error... (Error 0xc000012f).
Cheers

Re: DLL example?

Posted: Tue Apr 09, 2024 11:24 am
by DarkDragon
You need to compile it as dll and then as exe. The exe will call the procedure from the dll. See compiler options.

Image

Executable format: Shared DLL.

And it's not a PB only concept, DLLs/Shared Objects can be created with many other languages, too.

Re: DLL example?

Posted: Tue Apr 09, 2024 11:50 am
by charvista
Thank you DarkDragon ! :D
My very first DLL has been created !
And the CallFunction() worked as expected !
:wink: