michael@0: // Unicode support added by Jim Park -- 07/27/2007 michael@0: // Unicode support requires that all plugins take TCHARs instead as well. This michael@0: // means existing plugins will not work for the Unicode version of NSIS unless michael@0: // recompiled. You have been warned. michael@0: michael@0: #ifndef _EXDLL_H_ michael@0: #define _EXDLL_H_ michael@0: michael@0: #include michael@0: #include "tchar.h" michael@0: michael@0: #if defined(__GNUC__) michael@0: #define UNUSED __attribute__((unused)) michael@0: #else michael@0: #define UNUSED michael@0: #endif michael@0: michael@0: // only include this file from one place in your DLL. michael@0: // (it is all static, if you use it in two places it will fail) michael@0: michael@0: #define EXDLL_INIT() { \ michael@0: g_stringsize=string_size; \ michael@0: g_stacktop=stacktop; \ michael@0: g_variables=variables; } michael@0: michael@0: // For page showing plug-ins michael@0: #define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) michael@0: #define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) michael@0: michael@0: /* Jim Park: This char is compared as an int value and therefore michael@0: it's fine as an ASCII. Do not need to change to wchar_t since michael@0: it will get the same integer value. */ michael@0: #define NOTIFY_BYE_BYE _T('x') michael@0: michael@0: typedef struct _stack_t { michael@0: struct _stack_t *next; michael@0: TCHAR text[1]; // this should be the length of string_size michael@0: } stack_t; michael@0: michael@0: michael@0: static unsigned int g_stringsize; michael@0: static stack_t **g_stacktop; michael@0: static TCHAR *g_variables; michael@0: michael@0: static int __stdcall popstring(TCHAR *str) UNUSED; // 0 on success, 1 on empty stack michael@0: static void __stdcall pushstring(const TCHAR *str) UNUSED; michael@0: static TCHAR * __stdcall getuservariable(const int varnum) UNUSED; michael@0: static void __stdcall setuservariable(const int varnum, const TCHAR *var) UNUSED; michael@0: michael@0: enum michael@0: { michael@0: INST_0, // $0 michael@0: INST_1, // $1 michael@0: INST_2, // $2 michael@0: INST_3, // $3 michael@0: INST_4, // $4 michael@0: INST_5, // $5 michael@0: INST_6, // $6 michael@0: INST_7, // $7 michael@0: INST_8, // $8 michael@0: INST_9, // $9 michael@0: INST_R0, // $R0 michael@0: INST_R1, // $R1 michael@0: INST_R2, // $R2 michael@0: INST_R3, // $R3 michael@0: INST_R4, // $R4 michael@0: INST_R5, // $R5 michael@0: INST_R6, // $R6 michael@0: INST_R7, // $R7 michael@0: INST_R8, // $R8 michael@0: INST_R9, // $R9 michael@0: INST_CMDLINE, // $CMDLINE michael@0: INST_INSTDIR, // $INSTDIR michael@0: INST_OUTDIR, // $OUTDIR michael@0: INST_EXEDIR, // $EXEDIR michael@0: INST_LANG, // $LANGUAGE michael@0: __INST_LAST michael@0: }; michael@0: michael@0: typedef struct { michael@0: int autoclose; michael@0: int all_user_var; michael@0: int exec_error; michael@0: int abort; michael@0: int exec_reboot; michael@0: int reboot_called; michael@0: int XXX_cur_insttype; // deprecated michael@0: int XXX_insttype_changed; // deprecated michael@0: int silent; michael@0: int instdir_error; michael@0: int rtl; michael@0: int errlvl; michael@0: int alter_reg_view; michael@0: int status_update; michael@0: } exec_flags_type; michael@0: michael@0: typedef struct { michael@0: exec_flags_type *exec_flags; michael@0: int (__stdcall *ExecuteCodeSegment)(int, HWND); michael@0: void (__stdcall *validate_filename)(TCHAR *); michael@0: } extra_parameters; michael@0: michael@0: // utility functions (not required but often useful) michael@0: static int __stdcall popstring(TCHAR *str) michael@0: { michael@0: stack_t *th; michael@0: if (!g_stacktop || !*g_stacktop) return 1; michael@0: th=(*g_stacktop); michael@0: lstrcpy(str,th->text); michael@0: *g_stacktop = th->next; michael@0: GlobalFree((HGLOBAL)th); michael@0: return 0; michael@0: } michael@0: michael@0: static void __stdcall pushstring(const TCHAR *str) michael@0: { michael@0: stack_t *th; michael@0: if (!g_stacktop) return; michael@0: th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR))); michael@0: lstrcpyn(th->text,str,g_stringsize); michael@0: th->next=*g_stacktop; michael@0: *g_stacktop=th; michael@0: } michael@0: michael@0: static TCHAR * __stdcall getuservariable(const int varnum) michael@0: { michael@0: if (varnum < 0 || varnum >= __INST_LAST) return NULL; michael@0: return g_variables+varnum*g_stringsize; michael@0: } michael@0: michael@0: static void __stdcall setuservariable(const int varnum, const TCHAR *var) michael@0: { michael@0: if (var != NULL && varnum >= 0 && varnum < __INST_LAST) michael@0: lstrcpy(g_variables + varnum*g_stringsize, var); michael@0: } michael@0: michael@0: #ifdef _UNICODE michael@0: #define PopStringW(x) popstring(x) michael@0: #define PushStringW(x) pushstring(x) michael@0: #define SetUserVariableW(x,y) setuservariable(x,y) michael@0: michael@0: static int __stdcall PopStringA(char* ansiStr) michael@0: { michael@0: wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); michael@0: int rval = popstring(wideStr); michael@0: WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); michael@0: GlobalFree((HGLOBAL)wideStr); michael@0: return rval; michael@0: } michael@0: michael@0: static void __stdcall PushStringA(const char* ansiStr) michael@0: { michael@0: wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t)); michael@0: MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); michael@0: pushstring(wideStr); michael@0: GlobalFree((HGLOBAL)wideStr); michael@0: return; michael@0: } michael@0: michael@0: static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) michael@0: { michael@0: lstrcpyW(wideStr, getuservariable(varnum)); michael@0: } michael@0: michael@0: static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) michael@0: { michael@0: wchar_t* wideStr = getuservariable(varnum); michael@0: WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); michael@0: } michael@0: michael@0: static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr) michael@0: { michael@0: if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST) michael@0: { michael@0: wchar_t* wideStr = g_variables + varnum * g_stringsize; michael@0: MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); michael@0: } michael@0: } michael@0: michael@0: #else michael@0: // ANSI defs michael@0: michael@0: #define PopStringA(x) popstring(x) michael@0: #define PushStringA(x) pushstring(x) michael@0: #define SetUserVariableA(x,y) setuservariable(x,y) michael@0: michael@0: static int __stdcall PopStringW(wchar_t* wideStr) michael@0: { michael@0: char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); michael@0: int rval = popstring(ansiStr); michael@0: MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); michael@0: GlobalFree((HGLOBAL)ansiStr); michael@0: return rval; michael@0: } michael@0: michael@0: static void __stdcall PushStringW(wchar_t* wideStr) michael@0: { michael@0: char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize); michael@0: WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); michael@0: pushstring(ansiStr); michael@0: GlobalFree((HGLOBAL)ansiStr); michael@0: } michael@0: michael@0: static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr) michael@0: { michael@0: char* ansiStr = getuservariable(varnum); michael@0: MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize); michael@0: } michael@0: michael@0: static void __stdcall GetUserVariableA(const int varnum, char* ansiStr) michael@0: { michael@0: lstrcpyA(ansiStr, getuservariable(varnum)); michael@0: } michael@0: michael@0: static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr) michael@0: { michael@0: if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST) michael@0: { michael@0: char* ansiStr = g_variables + varnum * g_stringsize; michael@0: WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: static BOOL __stdcall IsUnicode(void) michael@0: { michael@0: #ifdef _UNICODE michael@0: return TRUE; michael@0: #else michael@0: return FALSE; michael@0: #endif michael@0: } michael@0: michael@0: #endif//_EXDLL_H_