Opening and calling DLL functions from inside a Purebasic DLL [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
AndyMK
Enthusiast
Enthusiast
Posts: 585
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Opening and calling DLL functions from inside a Purebasic DLL [SOLVED]

Post 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?
Last edited by AndyMK on Wed Dec 10, 2025 7:06 am, edited 1 time in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2267
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post by STARGÅTE »

Without any code or snippets nor information at which point the main DLL or sub DLL crashes?
Image
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 moreTypeface - Sprite-based font include/module
User avatar
idle
Always Here
Always Here
Posts: 6097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6415
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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()
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
AndyMK
Enthusiast
Enthusiast
Posts: 585
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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"?
User avatar
mk-soft
Always Here
Always Here
Posts: 6415
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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.
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
User avatar
skywalk
Addict
Addict
Posts: 4263
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
AndyMK
Enthusiast
Enthusiast
Posts: 585
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: Opening and calling DLL functions from inside a Purebasic DLL

Post 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.
Post Reply