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 GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h
|
---|
22 | #define GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h
|
---|
23 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
24 | # pragma once
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #include <iprt/win/windows.h>
|
---|
28 |
|
---|
29 | #if defined(__GNUC__)
|
---|
30 | #define UNUSED __attribute__((unused))
|
---|
31 | #else
|
---|
32 | #define UNUSED
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | // only include this file from one place in your DLL.
|
---|
36 | // (it is all static, if you use it in two places it will fail)
|
---|
37 |
|
---|
38 | #define EXDLL_INIT() { \
|
---|
39 | g_stringsize=string_size; \
|
---|
40 | g_stacktop=stacktop; \
|
---|
41 | g_variables=variables; }
|
---|
42 |
|
---|
43 | typedef struct _stack_t {
|
---|
44 | struct _stack_t *next;
|
---|
45 | char text[1]; // this should be the length of string_size
|
---|
46 | } stack_t;
|
---|
47 |
|
---|
48 |
|
---|
49 | static unsigned int g_stringsize;
|
---|
50 | static stack_t **g_stacktop;
|
---|
51 | static char *g_variables;
|
---|
52 |
|
---|
53 | static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack
|
---|
54 | static void __stdcall pushstring(const char *str) UNUSED;
|
---|
55 | static char * __stdcall getuservariable(const int varnum) UNUSED;
|
---|
56 | static void __stdcall setuservariable(const int varnum, const char *var) UNUSED;
|
---|
57 |
|
---|
58 | enum
|
---|
59 | {
|
---|
60 | INST_0, // $0
|
---|
61 | INST_1, // $1
|
---|
62 | INST_2, // $2
|
---|
63 | INST_3, // $3
|
---|
64 | INST_4, // $4
|
---|
65 | INST_5, // $5
|
---|
66 | INST_6, // $6
|
---|
67 | INST_7, // $7
|
---|
68 | INST_8, // $8
|
---|
69 | INST_9, // $9
|
---|
70 | INST_R0, // $R0
|
---|
71 | INST_R1, // $R1
|
---|
72 | INST_R2, // $R2
|
---|
73 | INST_R3, // $R3
|
---|
74 | INST_R4, // $R4
|
---|
75 | INST_R5, // $R5
|
---|
76 | INST_R6, // $R6
|
---|
77 | INST_R7, // $R7
|
---|
78 | INST_R8, // $R8
|
---|
79 | INST_R9, // $R9
|
---|
80 | INST_CMDLINE, // $CMDLINE
|
---|
81 | INST_INSTDIR, // $INSTDIR
|
---|
82 | INST_OUTDIR, // $OUTDIR
|
---|
83 | INST_EXEDIR, // $EXEDIR
|
---|
84 | INST_LANG, // $LANGUAGE
|
---|
85 | __INST_LAST
|
---|
86 | };
|
---|
87 |
|
---|
88 | // utility functions (not required but often useful)
|
---|
89 | static int __stdcall popstring(char *str)
|
---|
90 | {
|
---|
91 | stack_t *th;
|
---|
92 | if (!g_stacktop || !*g_stacktop)
|
---|
93 | return 1;
|
---|
94 | th=(*g_stacktop);
|
---|
95 | lstrcpyA(str,th->text);
|
---|
96 | *g_stacktop = th->next;
|
---|
97 | GlobalFree((HGLOBAL)th);
|
---|
98 | return 0;
|
---|
99 | }
|
---|
100 |
|
---|
101 | static void __stdcall pushstring(const char *str)
|
---|
102 | {
|
---|
103 | stack_t *th;
|
---|
104 | if (!g_stacktop)
|
---|
105 | return;
|
---|
106 | th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
---|
107 | lstrcpynA(th->text,str,g_stringsize);
|
---|
108 | th->next=*g_stacktop;
|
---|
109 | *g_stacktop=th;
|
---|
110 | }
|
---|
111 |
|
---|
112 | static char * __stdcall getuservariable(const int varnum)
|
---|
113 | {
|
---|
114 | if (varnum < 0 || varnum >= __INST_LAST)
|
---|
115 | return NULL;
|
---|
116 | return g_variables+varnum*g_stringsize;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static void __stdcall setuservariable(const int varnum, const char *var)
|
---|
120 | {
|
---|
121 | if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
---|
122 | lstrcpyA(g_variables + varnum*g_stringsize, var);
|
---|
123 | }
|
---|
124 | #endif /* !GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h */
|
---|