Restored from previous forum. Originally posted by marlo.
I want to test a simple DLL, and how is called the dll by another app. Anyone can make a simple, simple little code and how is called by another application?
I see the example file but i dont see wich are the commands to call the dll functions.
Thanks for help.
The example that comes with PB really dont help me.
from the ass of the world
Make a simple DLL
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
I don't know how you can get any simpler than the example that's provided with PB but here you go...
Start PB and type this:
This says we have a procedure called "message" and we pass a string to it. This string is then displayed in a MessageRequester and returns 1 if all is ok.
Now select "Compiler/Compiler" Options from the PB editor menu bar. Change the EXEC Format to "Shared DLL" and press OK.
Then select Compiler/Create Executable. Doesn't matter what you call it because after it is created it will be located in the PureBasic/Compilers Folder called PureBasic.DLL (you can manually rename this file to whatever you want)
Now start a new project and type this in:
Now select "Compiler/Compiler" Options from the PB editor menu bar. Make sure the EXEC Format is "Windows" and press OK.
Then select Compiler/Create Executable to create your executable. Put your created EXE in the same folder as your DLL (or make sure your DLL is in the Windows/System Folder)
So what happens here is when you start the EXE, it opens the DLL which we have named "purebasic.dll".
Remember in your DLL we named the Procedure "message" ?
So we call this function using CallFunction and start our little procedure "message" and pass the string "Hello World".
It is very important to notice that when calling procedures inside a DLL created with PureBasic, you must start your procedure name with "_" ... so "message" becomes "_message"
So, if you call your procedure and all goes well, it will display your text in a MessageRequester and return the value of 1 (meaning success). If it returns 0 then something went wrong and it will tell you.
Hope this helps a little.
I don't know how you can get any simpler than the example that's provided with PB but here you go...
Start PB and type this:
Code: Select all
ProcedureDLL message(text.s)
MessageRequester("Test DLL",text,#MB_ICONINFORMATION)
ProcedureReturn 1
EndProcedure
Now select "Compiler/Compiler" Options from the PB editor menu bar. Change the EXEC Format to "Shared DLL" and press OK.
Then select Compiler/Create Executable. Doesn't matter what you call it because after it is created it will be located in the PureBasic/Compilers Folder called PureBasic.DLL (you can manually rename this file to whatever you want)
Now start a new project and type this in:
Code: Select all
If OpenLibrary(0,"purebasic.dll")
If CallFunction(0,"_message","Hello World")=0
MessageRequester("Error","DLL Call Failed",#MB_ICONERROR)
EndIf
CloseLibrary(0)
EndIf
Then select Compiler/Create Executable to create your executable. Put your created EXE in the same folder as your DLL (or make sure your DLL is in the Windows/System Folder)
So what happens here is when you start the EXE, it opens the DLL which we have named "purebasic.dll".
Remember in your DLL we named the Procedure "message" ?
So we call this function using CallFunction and start our little procedure "message" and pass the string "Hello World".
It is very important to notice that when calling procedures inside a DLL created with PureBasic, you must start your procedure name with "_" ... so "message" becomes "_message"
So, if you call your procedure and all goes well, it will display your text in a MessageRequester and return the value of 1 (meaning success). If it returns 0 then something went wrong and it will tell you.
Hope this helps a little.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm