Archive: Plugin & Stack


Plugin & Stack
i need my plugin to be able to read to the NSIS stack as well as to write to the NSIS stack.

How do I do this? I am using C++.


http://nsis.svn.sourceforge.net/view...Contrib/ExDLL/


I know about exdll. How do I use that header to read & write to the stack?


popstring() and pushstring()


You mean like this:


pushstring("1");

and

var = popstring();

No, not like this. pushstring() is correct, but popstring() receives a buffer into which the string from the stack is written. It must be the size passed to your function as string_size.


pushstring() is not working with my plugin. Is there anything specific I must add to it?


you must call the exdll.h macro, EXDLL_INIT() inside your exported function


I get this error:

D:\Development Tools\Scripts\C++\dll\TG tests\tsts\mytestlibrary.cc: In function
`void Create()':
D:\Development Tools\Scripts\C++\dll\TG tests\tsts\mytestlibrary.cc:9: error: `s
tring_size' undeclared (first use this function)
D:\Development Tools\Scripts\C++\dll\TG tests\tsts\mytestlibrary.cc:9: error: (E
ach undeclared identifier is reported only once for each function it appears in.
)
D:\Development Tools\Scripts\C++\dll\TG tests\tsts\mytestlibrary.cc:9: error: `s
tacktop' undeclared (first use this function)
D:\Development Tools\Scripts\C++\dll\TG tests\tsts\mytestlibrary.cc:9: error: `v
ariables' undeclared (first use this function)

I have given up. There should be a "how to create a plugin in the NSIS manual"

Can anybody tell me how to use exdll? I have a function called Create in my dll and all I need is to be able to access the NSIS stack and read & write to the stack.


If you use only pop and push just add



/******************************************************************************
/* Defines *
******************************************************************************/
// for NSIS stack
#define EXDLL_INIT() \
{ \
g_stacktop = stacktop; \
g_variables = variables; \
g_stringsize = string_size; \
}
#define MAX_STRLEN 1024
/******************************************************************************
/* NSIS stack structure *
******************************************************************************/
typedef struct _stack_t {
struct _stack_t *next;
char text[MAX_STRLEN];
} stack_t;
/******************************************************************************
/* Global values *
******************************************************************************/
// for NSIS stack
stack_t **g_stacktop;
char *g_variables;
unsigned int g_stringsize;
/******************************************************************************
* FUNCTION NAME: pushstring *
* PARAMETER: STR *
* PURPOSE: Removes the element from the top of the NSIS stack and puts *
* it in the buffer. *
* RETURN: TRUE if stack is empty, FALSE if value is loaded. *
******************************************************************************/
int popstring(char *str)
{
stack_t *th;

if (!g_stacktop || !*g_stacktop) return 1;

th=(*g_stacktop);
lstrcpy(str,th->text);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);

return 0;
}
/******************************************************************************
* FUNCTION NAME: pushstring *
* PARAMETER: STR *
* PURPOSE: Adds an element to the top of the NSIS stack *
******************************************************************************/
void pushstring(const char *str)
{
stack_t *th;

if (!g_stacktop) return;

th=(stack_t*)GlobalAlloc(GPTR, sizeof(stack_t)+g_stringsize);
lstrcpyn(th->text,str,g_stringsize);
th->next=*g_stacktop;

*g_stacktop=th;
}



Don't forget to add an entry point with


extern "C"
void __declspec(dllexport) TheNameOfMyExternalFunction(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)


And to push result in your function ;)

To use in NSIS

myDLL::TheNameOfMyExternalFunction param1 param2 etc.

OK. It works now. Thanks