Page 1 of 1
Opening and calling DLL functions from inside a Purebasic DLL [SOLVED]
Posted: Tue Dec 09, 2025 7:17 pm
by AndyMK
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
Posted: Tue Dec 09, 2025 7:39 pm
by STARGĂ…TE
Without any code or snippets nor information at which point the main DLL or sub DLL crashes?

No!
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Tue Dec 09, 2025 8:42 pm
by idle
AndyMK 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?
Is it a case of structure alignment? have you tried with Align #PB_Structure_AlignC
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Tue Dec 09, 2025 8:43 pm
by mk-soft
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
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
or
Code: Select all
Procedure InitMyDLL()
;TODO
EndProcedure : InitMyDLL()
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Tue Dec 09, 2025 9:51 pm
by AndyMK
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"?
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Tue Dec 09, 2025 11:40 pm
by mk-soft
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"?
Everything Stack needs. Value allocations, string distribution, calculations, etc.
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Wed Dec 10, 2025 12:01 am
by skywalk
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.
Re: Opening and calling DLL functions from inside a Purebasic DLL
Posted: Wed Dec 10, 2025 7:05 am
by AndyMK
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.