How are DLLs correctly programmed?
Posted: Fri Apr 01, 2016 6:50 pm
The PB help says:The list must be declared globally:
On Linux, the procedure "AttachProcess" is not performed automatically when the library opens.
This way is incorrect, because code exists outside procedures:It only remains this way:
Is that all right? How is it correct?
If I follow these rules, that isn't allowed:Notes about creating DLL's:
- The declaration of arrays, lists or map with Dim, NewList or NewMap must always be done inside the procedure AttachProcess.
- Don't write program code outside procedures. The only exception is the declaration of variables or structures.
- DirectX initialization routines must not be written in the AttachProcess procedure.
Code: Select all
Procedure Test()
Protected NewList MyList.s()
...
EndProcedure
Code: Select all
Procedure AttachProcess(Instance)
Global NewList MyList.s()
EndProcedure
Procedure Test()
... MyList() ...
EndProcedure
This way is incorrect, because code exists outside procedures:
Code: Select all
Procedure AttachProcess(Instance)
Global NewList MyList.s()
EndProcedure
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
AttachProcess(0)
CompilerEndIf
Procedure Test()
... MyList() ...
EndProcedure
Code: Select all
OpenLibrary(0, "DLLPath")
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CallFunction(0, "AttachProcess", 0)
CompilerEndIf
...