Code: Select all
; Minimal PureBasic NSIS plugin for stack handling test
; In this example compiled with /UNICODE and as x86.
; Filename: TestPlugin.dll
Structure stack_t
*Next.stack_t
text.s{1024}
EndStructure
Procedure.s PopString(*stacktop_pointer)
Protected result.s = ""
Protected *stacktop.stack_t = PeekI(*stacktop_pointer)
If *stacktop
result = PeekS(@*stacktop\text, 1024)
PokeI(*stacktop_pointer, *stacktop\Next)
GlobalFree_(*stacktop)
EndIf
ProcedureReturn result
EndProcedure
Procedure PushString(str.s, *stacktop_pointer)
Protected *new.stack_t = GlobalAlloc_(#GMEM_FIXED, SizeOf(stack_t))
If *new
PokeS(@*new\text, str, 1024)
*new\Next = PeekI(*stacktop_pointer)
PokeI(*stacktop_pointer, *new)
EndIf
EndProcedure
ProcedureCDLL TestPlugin(hwndParent, string_size, *variables, *stacktop, *extra)
Protected *stacktop_pointer = *stacktop
Protected param.s = PopString(*stacktop_pointer)
MessageRequester("TestPlugin", param)
PushString("42", *stacktop_pointer)
EndProcedure
Code: Select all
; Minimal NSIS script to test the PureBasic TestPlugin DLL
; Assuming the TestPlugin.dll has been placed in the NSIS\Plugins\x86-unicode folder
Unicode True
Name "TestPlugin Test"
OutFile "TestPluginTest.exe"
Section "Test TestPlugin"
DetailPrint "Calling TestPlugin with parameter: HelloFromNSIS"
TestPlugin::TestPlugin "HelloFromNSIS"
Pop $0
DetailPrint "TestPlugin result: $0"
; Will output "42", as a string since all return values in NSIS are strings
SectionEnd