Opening and calling DLL functions from inside a Purebasic DLL [SOLVED]
Opening and calling DLL functions from inside a Purebasic DLL [SOLVED]
I am having trouble calling dll functions from my purebasic dll. If i create a simple dll procedure and export as a dll then call it from another process, it works fine. If i try to load a dll inside my dll, for example portaudio and wrap a portaudio function, calling the wrapped function from another process, crashes the dll. Does anyone have any tips?
Last edited by AndyMK on Wed Dec 10, 2025 7:06 am, edited 1 time in total.
Re: Opening and calling DLL functions from inside a Purebasic DLL
Without any code or snippets nor information at which point the main DLL or sub DLL crashes?

No!

No!
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Opening and calling DLL functions from inside a Purebasic DLL
Is it a case of structure alignment? have you tried with Align #PB_Structure_AlignCAndyMK wrote: Tue Dec 09, 2025 7:17 pm I am having trouble calling dll functions from my purebasic dll. If i create a simple dll procedure and export as a dll then call it from another process, it works fine. If i try to load a dll inside my dll, for example portaudio and wrap a portaudio function, calling the wrapped function from another process, crashes the dll. Does anyone have any tips?
Re: Opening and calling DLL functions from inside a Purebasic DLL
Never done before.
But what is important is that no code is written outside of procedures. Otherwise, the DLL will crash.
According to PB help example
or
But what is important is that no code is written outside of procedures. Otherwise, the DLL will crash.
According to PB help example
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; These 4 procedures are Windows specific
;
; 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
CompilerEndIf
Code: Select all
Procedure InitMyDLL()
;TODO
EndProcedure : InitMyDLL()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Opening and calling DLL functions from inside a Purebasic DLL
I got it working. The dll i was calling had to be placed in the same directory as the calling process which is not Purebasic.
Godot -> calling pb dll -> calling another dll. <- this dll should be in the same dir as the Godot exe. It was in a separate folder with the pb source.
@mk-soft "But what is important is that no code is written outside of procedures"
What is classed as "code"?
Godot -> calling pb dll -> calling another dll. <- this dll should be in the same dir as the Godot exe. It was in a separate folder with the pb source.
@mk-soft "But what is important is that no code is written outside of procedures"
What is classed as "code"?
Re: Opening and calling DLL functions from inside a Purebasic DLL
Everything Stack needs. Value allocations, string distribution, calculations, etc.AndyMK wrote: Tue Dec 09, 2025 9:51 pm @mk-soft "But what is important is that no code is written outside of procedures"
What is classed as "code"?
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Opening and calling DLL functions from inside a Purebasic DLL
Yes, just put all code in procedures.
If windows, there are attach and detach dll procedures you can run init codes. Or just make an init() proceduredll you call from your app.
If windows, there are attach and detach dll procedures you can run init codes. Or just make an init() proceduredll you call from your app.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Opening and calling DLL functions from inside a Purebasic DLL
I have IncludeFiles that contain variable allocations and macros at the top of my code and it seems to run fine. I put openlibrary stuff in a Procedure and globally allocated functions.


