1 | /*
|
---|
2 | * Copyright (C) 1995-2009 Contributors
|
---|
3 | * More detailed copyright information can be found in the individual source code files.
|
---|
4 | *
|
---|
5 | * This software is provided 'as-is', without any express or implied warranty.
|
---|
6 | * In no event will the authors be held liable for any damages arising from the use of this software.
|
---|
7 | *
|
---|
8 | * Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter
|
---|
9 | * it and redistribute it freely, subject to the following restrictions:
|
---|
10 | *
|
---|
11 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
|
---|
12 | * If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
---|
13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
---|
14 | * 3. This notice may not be removed or altered from any source distribution.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /** Taken from:
|
---|
18 | * http://nsis.sourceforge.net/Examples/Plugin/exdll.h
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef _EXDLL_H_
|
---|
22 | #define _EXDLL_H_
|
---|
23 |
|
---|
24 | #include <windows.h>
|
---|
25 |
|
---|
26 | #if defined(__GNUC__)
|
---|
27 | #define UNUSED __attribute__((unused))
|
---|
28 | #else
|
---|
29 | #define UNUSED
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | // only include this file from one place in your DLL.
|
---|
33 | // (it is all static, if you use it in two places it will fail)
|
---|
34 |
|
---|
35 | #define EXDLL_INIT() { \
|
---|
36 | g_stringsize=string_size; \
|
---|
37 | g_stacktop=stacktop; \
|
---|
38 | g_variables=variables; }
|
---|
39 |
|
---|
40 | typedef struct _stack_t {
|
---|
41 | struct _stack_t *next;
|
---|
42 | char text[1]; // this should be the length of string_size
|
---|
43 | } stack_t;
|
---|
44 |
|
---|
45 |
|
---|
46 | static unsigned int g_stringsize;
|
---|
47 | static stack_t **g_stacktop;
|
---|
48 | static char *g_variables;
|
---|
49 |
|
---|
50 | static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack
|
---|
51 | static void __stdcall pushstring(const char *str) UNUSED;
|
---|
52 | static char * __stdcall getuservariable(const int varnum) UNUSED;
|
---|
53 | static void __stdcall setuservariable(const int varnum, const char *var) UNUSED;
|
---|
54 |
|
---|
55 | enum
|
---|
56 | {
|
---|
57 | INST_0, // $0
|
---|
58 | INST_1, // $1
|
---|
59 | INST_2, // $2
|
---|
60 | INST_3, // $3
|
---|
61 | INST_4, // $4
|
---|
62 | INST_5, // $5
|
---|
63 | INST_6, // $6
|
---|
64 | INST_7, // $7
|
---|
65 | INST_8, // $8
|
---|
66 | INST_9, // $9
|
---|
67 | INST_R0, // $R0
|
---|
68 | INST_R1, // $R1
|
---|
69 | INST_R2, // $R2
|
---|
70 | INST_R3, // $R3
|
---|
71 | INST_R4, // $R4
|
---|
72 | INST_R5, // $R5
|
---|
73 | INST_R6, // $R6
|
---|
74 | INST_R7, // $R7
|
---|
75 | INST_R8, // $R8
|
---|
76 | INST_R9, // $R9
|
---|
77 | INST_CMDLINE, // $CMDLINE
|
---|
78 | INST_INSTDIR, // $INSTDIR
|
---|
79 | INST_OUTDIR, // $OUTDIR
|
---|
80 | INST_EXEDIR, // $EXEDIR
|
---|
81 | INST_LANG, // $LANGUAGE
|
---|
82 | __INST_LAST
|
---|
83 | };
|
---|
84 |
|
---|
85 | // utility functions (not required but often useful)
|
---|
86 | static int __stdcall popstring(char *str)
|
---|
87 | {
|
---|
88 | stack_t *th;
|
---|
89 | if (!g_stacktop || !*g_stacktop)
|
---|
90 | return 1;
|
---|
91 | th=(*g_stacktop);
|
---|
92 | lstrcpyA(str,th->text);
|
---|
93 | *g_stacktop = th->next;
|
---|
94 | GlobalFree((HGLOBAL)th);
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static void __stdcall pushstring(const char *str)
|
---|
99 | {
|
---|
100 | stack_t *th;
|
---|
101 | if (!g_stacktop)
|
---|
102 | return;
|
---|
103 | th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
---|
104 | lstrcpynA(th->text,str,g_stringsize);
|
---|
105 | th->next=*g_stacktop;
|
---|
106 | *g_stacktop=th;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static char * __stdcall getuservariable(const int varnum)
|
---|
110 | {
|
---|
111 | if (varnum < 0 || varnum >= __INST_LAST)
|
---|
112 | return NULL;
|
---|
113 | return g_variables+varnum*g_stringsize;
|
---|
114 | }
|
---|
115 |
|
---|
116 | static void __stdcall setuservariable(const int varnum, const char *var)
|
---|
117 | {
|
---|
118 | if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
---|
119 | lstrcpyA(g_variables + varnum*g_stringsize, var);
|
---|
120 | }
|
---|
121 | #endif//_EXDLL_H_
|
---|