Couple different ways. Here I'm declaring a global var in a dll and accessing it in two different ways: (1) passing its address in an Init() procedure, after which the var will be accessible via PeekI() and (2) creating a function to return the var, which can be called any time you want the var's value.
Code:
; DLL code:
ProcedureDLL AttachProcess(instance)
Global this.i = 123
EndProcedure
ProcedureDLL Init()
ProcedureReturn @this
EndProcedure
ProcedureDLL GetThis()
ProcedureReturn this
EndProcedure
Code:
; Calling code
Prototype Init()
Prototype GetThis()
OpenLibrary(0, "c:\test.dll")
Init.Init = GetFunction(0, "Init")
Getthis.Getthis = GetFunction(0, "GetThis")
*ptr_i = Init()
Debug PeekI(*ptr_i)*2
Debug GetThis()*2
I have the global declaration inside the AttachProcess function, but it doesn't need to be there. It can just be declared normally at the top of the code.