1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,234 @@ 1.4 +// Unicode support added by Jim Park -- 07/27/2007 1.5 +// Unicode support requires that all plugins take TCHARs instead as well. This 1.6 +// means existing plugins will not work for the Unicode version of NSIS unless 1.7 +// recompiled. You have been warned. 1.8 + 1.9 +#ifndef _EXDLL_H_ 1.10 +#define _EXDLL_H_ 1.11 + 1.12 +#include <windows.h> 1.13 +#include "tchar.h" 1.14 + 1.15 +#if defined(__GNUC__) 1.16 +#define UNUSED __attribute__((unused)) 1.17 +#else 1.18 +#define UNUSED 1.19 +#endif 1.20 + 1.21 +// only include this file from one place in your DLL. 1.22 +// (it is all static, if you use it in two places it will fail) 1.23 + 1.24 +#define EXDLL_INIT() { \ 1.25 + g_stringsize=string_size; \ 1.26 + g_stacktop=stacktop; \ 1.27 + g_variables=variables; } 1.28 + 1.29 +// For page showing plug-ins 1.30 +#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) 1.31 +#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) 1.32 + 1.33 +/* Jim Park: This char is compared as an int value and therefore 1.34 + it's fine as an ASCII. Do not need to change to wchar_t since 1.35 + it will get the same integer value. */ 1.36 +#define NOTIFY_BYE_BYE _T('x') 1.37 + 1.38 +typedef struct _stack_t { 1.39 + struct _stack_t *next; 1.40 + TCHAR text[1]; // this should be the length of string_size 1.41 +} stack_t; 1.42 + 1.43 + 1.44 +static unsigned int g_stringsize; 1.45 +static stack_t **g_stacktop; 1.46 +static TCHAR *g_variables; 1.47 + 1.48 +static int __stdcall popstring(TCHAR *str) UNUSED; // 0 on success, 1 on empty stack 1.49 +static void __stdcall pushstring(const TCHAR *str) UNUSED; 1.50 +static TCHAR * __stdcall getuservariable(const int varnum) UNUSED; 1.51 +static void __stdcall setuservariable(const int varnum, const TCHAR *var) UNUSED; 1.52 + 1.53 +enum 1.54 +{ 1.55 +INST_0, // $0 1.56 +INST_1, // $1 1.57 +INST_2, // $2 1.58 +INST_3, // $3 1.59 +INST_4, // $4 1.60 +INST_5, // $5 1.61 +INST_6, // $6 1.62 +INST_7, // $7 1.63 +INST_8, // $8 1.64 +INST_9, // $9 1.65 +INST_R0, // $R0 1.66 +INST_R1, // $R1 1.67 +INST_R2, // $R2 1.68 +INST_R3, // $R3 1.69 +INST_R4, // $R4 1.70 +INST_R5, // $R5 1.71 +INST_R6, // $R6 1.72 +INST_R7, // $R7 1.73 +INST_R8, // $R8 1.74 +INST_R9, // $R9 1.75 +INST_CMDLINE, // $CMDLINE 1.76 +INST_INSTDIR, // $INSTDIR 1.77 +INST_OUTDIR, // $OUTDIR 1.78 +INST_EXEDIR, // $EXEDIR 1.79 +INST_LANG, // $LANGUAGE 1.80 +__INST_LAST 1.81 +}; 1.82 + 1.83 +typedef struct { 1.84 + int autoclose; 1.85 + int all_user_var; 1.86 + int exec_error; 1.87 + int abort; 1.88 + int exec_reboot; 1.89 + int reboot_called; 1.90 + int XXX_cur_insttype; // deprecated 1.91 + int XXX_insttype_changed; // deprecated 1.92 + int silent; 1.93 + int instdir_error; 1.94 + int rtl; 1.95 + int errlvl; 1.96 + int alter_reg_view; 1.97 + int status_update; 1.98 +} exec_flags_type; 1.99 + 1.100 +typedef struct { 1.101 + exec_flags_type *exec_flags; 1.102 + int (__stdcall *ExecuteCodeSegment)(int, HWND); 1.103 + void (__stdcall *validate_filename)(TCHAR *); 1.104 +} extra_parameters; 1.105 + 1.106 +// utility functions (not required but often useful) 1.107 +static int __stdcall popstring(TCHAR *str) 1.108 +{ 1.109 + stack_t *th; 1.110 + if (!g_stacktop || !*g_stacktop) return 1; 1.111 + th=(*g_stacktop); 1.112 + lstrcpy(str,th->text); 1.113 + *g_stacktop = th->next; 1.114 + GlobalFree((HGLOBAL)th); 1.115 + return 0; 1.116 +} 1.117 + 1.118 +static void __stdcall pushstring(const TCHAR *str) 1.119 +{ 1.120 + stack_t *th; 1.121 + if (!g_stacktop) return; 1.122 + th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR))); 1.123 + lstrcpyn(th->text,str,g_stringsize); 1.124 + th->next=*g_stacktop; 1.125 + *g_stacktop=th; 1.126 +} 1.127 + 1.128 +static TCHAR * __stdcall getuservariable(const int varnum) 1.129 +{ 1.130 + if (varnum < 0 || varnum >= __INST_LAST) return NULL; 1.131 + return g_variables+varnum*g_stringsize; 1.132 +} 1.133 + 1.134 +static void __stdcall setuservariable(const int varnum, const TCHAR *var) 1.135 +{ 1.136 + if (var != NULL && varnum >= 0 && varnum < __INST_LAST) 1.137 + lstrcpy(g_variables + varnum*g_stringsize, var); 1.138 +} 1.139 + 1.140 +#ifdef _UNICODE 1.141 +#define PopStringW(x) popstring(x) 1.142 +#define PushStringW(x) pushstring(x) 1.143 +#define SetUserVariableW(x,y) setuservariable(x,y) 1.144 + 1.145 +static int __stdcall PopStringA(char* ansiStr) 1.146 +{ 1.147 + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); 1.148 + int rval = popstring(wideStr); 1.149 + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); 1.150 + GlobalFree((HGLOBAL)wideStr); 1.151 + return rval; 1.152 +} 1.153 + 1.154 +static void __stdcall PushStringA(const char* ansiStr) 1.155 +{ 1.156 + wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); 1.157 + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); 1.158 + pushstring(wideStr); 1.159 + GlobalFree((HGLOBAL)wideStr); 1.160 + return; 1.161 +} 1.162 + 1.163 +static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) 1.164 +{ 1.165 + lstrcpyW(wideStr, getuservariable(varnum)); 1.166 +} 1.167 + 1.168 +static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) 1.169 +{ 1.170 + wchar_t* wideStr = getuservariable(varnum); 1.171 + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); 1.172 +} 1.173 + 1.174 +static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr) 1.175 +{ 1.176 + if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST) 1.177 + { 1.178 + wchar_t* wideStr = g_variables + varnum * g_stringsize; 1.179 + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); 1.180 + } 1.181 +} 1.182 + 1.183 +#else 1.184 +// ANSI defs 1.185 + 1.186 +#define PopStringA(x) popstring(x) 1.187 +#define PushStringA(x) pushstring(x) 1.188 +#define SetUserVariableA(x,y) setuservariable(x,y) 1.189 + 1.190 +static int __stdcall PopStringW(wchar_t* wideStr) 1.191 +{ 1.192 + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); 1.193 + int rval = popstring(ansiStr); 1.194 + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); 1.195 + GlobalFree((HGLOBAL)ansiStr); 1.196 + return rval; 1.197 +} 1.198 + 1.199 +static void __stdcall PushStringW(wchar_t* wideStr) 1.200 +{ 1.201 + char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); 1.202 + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); 1.203 + pushstring(ansiStr); 1.204 + GlobalFree((HGLOBAL)ansiStr); 1.205 +} 1.206 + 1.207 +static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) 1.208 +{ 1.209 + char* ansiStr = getuservariable(varnum); 1.210 + MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); 1.211 +} 1.212 + 1.213 +static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) 1.214 +{ 1.215 + lstrcpyA(ansiStr, getuservariable(varnum)); 1.216 +} 1.217 + 1.218 +static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr) 1.219 +{ 1.220 + if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST) 1.221 + { 1.222 + char* ansiStr = g_variables + varnum * g_stringsize; 1.223 + WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); 1.224 + } 1.225 +} 1.226 +#endif 1.227 + 1.228 +static BOOL __stdcall IsUnicode(void) 1.229 +{ 1.230 +#ifdef _UNICODE 1.231 + return TRUE; 1.232 +#else 1.233 + return FALSE; 1.234 +#endif 1.235 +} 1.236 + 1.237 +#endif//_EXDLL_H_