DLL Export global variable string

Just starting out? Need help? Post your questions and find answers here.
devox
User
User
Posts: 32
Joined: Thu Apr 01, 2021 7:25 pm

DLL Export global variable string

Post by devox »

Hi,

I'm writing a plugin which is a DLL and the DLL exports some global variables. Here is the C version.

Code: Select all

// This from header file used by plugin.
#define EXTERN_C
#define DSP_EXPORT EXTERN_C __declspec(dllexport)
typedef char const*     string;

Code: Select all

// This is from the c file and has what is exported in the DLL.
DSP_EXPORT string const name="Script Name";
DSP_EXPORT string description="Script Description";
I'm trying to do the equivalent of above in PB?
devox
User
User
Posts: 32
Joined: Thu Apr 01, 2021 7:25 pm

Re: DLL Export global variable string

Post by devox »

After much playing around I'm managing to figure it out somewhat with this code.

Code: Select all

ImportC "/EXPORT:name" : EndImport
ImportC "/EXPORT:description" : EndImport

! public v_name as 'name'
Global name.s = "Purebasic"
! public v_description as 'description'
Global description.s = "Purebasic"


ProcedureDLL AttachProcess(Instance)

EndProcedure

ProcedureDLL DetachProcess(Instance)
EndProcedure
It seems the strings in purebasic are unicode is it possible to specify it as Ascii?
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: DLL Export global variable string

Post by fryquez »

As long as PureBasic uses fasm:

Code: Select all

ImportC "/EXPORT:name" : EndImport
ImportC "/EXPORT:description" : EndImport

ProcedureDLL AttachProcess(Instance)
  
  ProcedureReturn 1
  !public _ASCCI_String1 as 'name'
  !public _ASCCI_String2 as 'description'
  
  !Align 4
  !_ASCCI_String1:
  !db "Hello", 0
  
  !Align 4
  !_ASCCI_String2:
  !db "World", 0
  
EndProcedure
Post Reply