VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/exdll.h@ 82625

Last change on this file since 82625 was 82625, checked in by vboxsync, 4 years ago

Windows Additions/Installer: More work required for the VBoxGuestInstallHelper plugin to respect ANSI/Unicode with NSIS 3.x (NSIS uses TCHAR), extended the testcase, bugref:9529.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
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// Starting with NSIS 2.42, you can check the version of the plugin API in exec_flags->plugin_api_version
36// The format is 0xXXXXYYYY where X is the major version and Y is the minor version (MAKELONG(y,x))
37// When doing version checks, always remember to use >=, ex: if (pX->exec_flags->plugin_api_version >= NSISPIAPIVER_1_0) {}
38
39#define NSISPIAPIVER_1_0 0x00010000
40#define NSISPIAPIVER_CURR NSISPIAPIVER_1_0
41
42// NSIS Plug-In Callback Messages
43enum NSPIM
44{
45 NSPIM_UNLOAD, // This is the last message a plugin gets, do final cleanup
46 NSPIM_GUIUNLOAD, // Called after .onGUIEnd
47};
48
49/** Defines the maximum string length NSIS can handle.
50 * Note: This depends on the NSIS build being used, e.g. there are different builds which can also handle larger strings.
51 * So to play safe go with the minimum (default) string length here. */
52#define NSIS_MAX_STRLEN 1024
53
54// Prototype for callbacks registered with extra_parameters->RegisterPluginCallback()
55// Return NULL for unknown messages
56// Should always be __cdecl for future expansion possibilities
57typedef UINT_PTR (*NSISPLUGINCALLBACK)(enum NSPIM);
58
59#ifndef NSISCALL
60# define NSISCALL __stdcall
61#endif
62
63// only include this file from one place in your DLL.
64// (it is all static, if you use it in two places it will fail)
65
66#define EXDLL_INIT() { \
67 g_stringsize=string_size; \
68 g_stacktop=stacktop; \
69 g_variables=variables; }
70
71typedef struct _stack_t
72{
73 struct _stack_t *next;
74 TCHAR text[1]; // this should be the length of string_size
75} stack_t;
76
77// extra_parameters data structures containing other interesting stuff
78// but the stack, variables and HWND passed on to plug-ins.
79typedef struct
80{
81 int autoclose;
82 int all_user_var;
83 int exec_error;
84 int abort;
85 int exec_reboot; // NSIS_SUPPORT_REBOOT
86 int reboot_called; // NSIS_SUPPORT_REBOOT
87 int XXX_cur_insttype; // depreacted
88 int plugin_api_version; // see NSISPIAPIVER_CURR
89 // used to be XXX_insttype_changed
90 int silent; // NSIS_CONFIG_SILENT_SUPPORT
91 int instdir_error;
92 int rtl;
93 int errlvl;
94 int alter_reg_view;
95 int status_update;
96} exec_flags_t;
97
98typedef struct
99{
100 exec_flags_t *exec_flags;
101 int (NSISCALL *ExecuteCodeSegment)(int, HWND);
102 void (NSISCALL *validate_filename)(TCHAR *);
103 BOOL (NSISCALL *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK);
104} extra_parameters;
105
106static unsigned int g_stringsize;
107static stack_t **g_stacktop;
108static TCHAR *g_variables;
109
110enum
111{
112INST_0, // $0
113INST_1, // $1
114INST_2, // $2
115INST_3, // $3
116INST_4, // $4
117INST_5, // $5
118INST_6, // $6
119INST_7, // $7
120INST_8, // $8
121INST_9, // $9
122INST_R0, // $R0
123INST_R1, // $R1
124INST_R2, // $R2
125INST_R3, // $R3
126INST_R4, // $R4
127INST_R5, // $R5
128INST_R6, // $R6
129INST_R7, // $R7
130INST_R8, // $R8
131INST_R9, // $R9
132INST_CMDLINE, // $CMDLINE
133INST_INSTDIR, // $INSTDIR
134INST_OUTDIR, // $OUTDIR
135INST_EXEDIR, // $EXEDIR
136INST_LANG, // $LANGUAGE
137__INST_LAST
138};
139
140// utility functions (not required but often useful)
141int popstringn(TCHAR *str, int maxlen)
142{
143 stack_t *th;
144 if (!g_stacktop || !*g_stacktop) return 1;
145 th=(*g_stacktop);
146 if (str) lstrcpyn(str,th->text,maxlen?maxlen:g_stringsize);
147 *g_stacktop = th->next;
148 GlobalFree((HGLOBAL)th);
149 return 0;
150}
151
152static void __stdcall pushstring(const TCHAR *str)
153{
154 stack_t *th;
155 if (!g_stacktop)
156 return;
157 th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
158 lstrcpyn(th->text,str,g_stringsize);
159 th->next=*g_stacktop;
160 *g_stacktop=th;
161}
162
163static TCHAR* __stdcall getuservariable(const int varnum)
164{
165 if (varnum < 0 || varnum >= __INST_LAST)
166 return NULL;
167 return g_variables+varnum*g_stringsize;
168}
169
170static void __stdcall setuservariable(const int varnum, const TCHAR *var)
171{
172 if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
173 lstrcpy(g_variables + varnum*g_stringsize, var);
174}
175#endif /* !GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use