DLL example?

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

DLL example?

Post 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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: DLL example?

Post 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.
bye,
Daniel
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: DLL example?

Post by charvista »

Thank you DarkDragon ! :D
My very first DLL has been created !
And the CallFunction() worked as expected !
:wink:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply