NSIS-DLL with Purebasic

Windows specific forum
sepp
User
User
Posts: 10
Joined: Sat Jul 28, 2012 11:31 pm

NSIS-DLL with Purebasic

Post by sepp »

Hello all,

I'm wondering if anyone has tried to create a NSIS-DLL with Purebasic and can share it here?
I was able to call the function in the DLL, but I am not able to pass a parameter.

Thanks,
Sepp

Example C-Plugin:
http://nsis.sourceforge.net/Examples/Plugin/

dlltest.nsi

Code: Select all

!addplugindir "."

Name "DLL-Test"
OutFile "dlltest.exe"
RequestExecutionLevel user
SilentInstall silent

Section
  MessageBox MB_OK "This is an internal MessageBox"
  dlltest::testprocedure "This is an DLL MessageBox with NSI-parameter"
SectionEnd
dlltest.pb

Code: Select all

Structure TCHAR
 *Pointer.c
EndStructure

Structure stack_t
  *Next.stack_t
  text.s
EndStructure

ProcedureDLL testprocedure(hwndParent.i, string_size.i, *variables.TCHAR, *stacktop.stack_t, *extra)
  MessageRequester("testprocedure", Str(hwndParent) + ", " + Str(string_size.i) + "," + *stacktop\text + ", " + Str(*stacktop\Next))
EndProcedure

; IDE Options = PureBasic 4.61 (Windows - x86)
; ExecutableFormat = Shared Dll
; CursorPosition = 12
; Folding = -
; Executable = dlltest.dll
; CPU = 1
sepp
User
User
Posts: 10
Joined: Sat Jul 28, 2012 11:31 pm

Re: NSIS-DLL with Purebasic

Post by sepp »

Got a little bit further, parameter passing works now, but created Exe is always crashing with errocode 0xc0000005.
Any ideas?

dlltest.pb

Code: Select all

Structure TCHAR
 char.i
EndStructure

Structure stack_t
  *Next.stack_t
  text.s{1024}
EndStructure

ProcedureDLL testprocedure(hwndParent.i, string_size.i, *variables.TCHAR, *stacktop_pointer, *extra)
  *stacktop.stack_t = PeekI(*stacktop_pointer)
  *stacktop_pointer = *stacktop\Next ; Decrease Stack
  MessageRequester("testprocedure", *stacktop\text)
EndProcedure
sepp
User
User
Posts: 10
Joined: Sat Jul 28, 2012 11:31 pm

Re: NSIS-DLL with Purebasic

Post by sepp »

Got it now with help of the NSIS-forum: NSIS-DLL's must use the cdecl calling convention (Windows-default is stdcall) whereas the calling function cleans the stack (at stdcall the callee cleans the stack).

So ProcedureCDLL must be used instead of ProcedureDLL, that's it :D

dlltest.pb

Code: Select all

Structure TCHAR
 char.i
EndStructure

Structure stack_t
  *Next.stack_t
  text.s{1024}
EndStructure

ProcedureCDLL testprocedure(hwndParent.i, string_size.i, *variables.TCHAR, *stacktop_pointer, *extra)
  *stacktop.stack_t = PeekI(*stacktop_pointer)
  *stacktop_pointer = *stacktop\Next ; Decrease Stack
  MessageRequester("testprocedure", *stacktop\text)
EndProcedure

; IDE Options = PureBasic 4.61 (Windows - x86)
; ExecutableFormat = Shared Dll
; CursorPosition = 9
; Folding = -
; Executable = dlltest.dll
; CPU = 1
Post Reply