exdll.h (2383B)
1 #ifndef _EXDLL_H_ 2 #define _EXDLL_H_ 3 4 // only include this file from one place in your DLL. 5 // (it is all static, if you use it in two places it will fail) 6 7 #define EXDLL_INIT() { \ 8 g_stringsize=string_size; \ 9 g_stacktop=stacktop; \ 10 g_variables=variables; } 11 12 // For page showing plug-ins 13 #define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) 14 #define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) 15 #define NOTIFY_BYE_BYE 'x' 16 17 typedef struct _stack_t { 18 struct _stack_t *next; 19 TCHAR text[1]; // this should be the length of string_size 20 } stack_t; 21 22 23 static unsigned int g_stringsize; 24 static stack_t **g_stacktop; 25 static TCHAR *g_variables; 26 27 static int __stdcall popstring(TCHAR *str); // 0 on success, 1 on empty stack 28 static void __stdcall pushstring(const TCHAR *str); 29 30 enum 31 { 32 INST_0, // $0 33 INST_1, // $1 34 INST_2, // $2 35 INST_3, // $3 36 INST_4, // $4 37 INST_5, // $5 38 INST_6, // $6 39 INST_7, // $7 40 INST_8, // $8 41 INST_9, // $9 42 INST_R0, // $R0 43 INST_R1, // $R1 44 INST_R2, // $R2 45 INST_R3, // $R3 46 INST_R4, // $R4 47 INST_R5, // $R5 48 INST_R6, // $R6 49 INST_R7, // $R7 50 INST_R8, // $R8 51 INST_R9, // $R9 52 INST_CMDLINE, // $CMDLINE 53 INST_INSTDIR, // $INSTDIR 54 INST_OUTDIR, // $OUTDIR 55 INST_EXEDIR, // $EXEDIR 56 INST_LANG, // $LANGUAGE 57 __INST_LAST 58 }; 59 60 61 // utility functions (not required but often useful) 62 static int __stdcall popstring(TCHAR *str) 63 { 64 stack_t *th; 65 if (!g_stacktop || !*g_stacktop) return 1; 66 th=(*g_stacktop); 67 lstrcpy(str,th->text); 68 *g_stacktop = th->next; 69 GlobalFree((HGLOBAL)th); 70 return 0; 71 } 72 73 static void __stdcall pushstring(const TCHAR *str) 74 { 75 stack_t *th; 76 if (!g_stacktop) return; 77 th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize*sizeof(TCHAR)); 78 lstrcpyn(th->text,str,g_stringsize); 79 th->next=*g_stacktop; 80 *g_stacktop=th; 81 } 82 83 static TCHAR * __stdcall getuservariable(int varnum) 84 { 85 if (varnum < 0 || varnum >= __INST_LAST) return NULL; 86 return g_variables+varnum*g_stringsize; 87 } 88 89 static void __stdcall setuservariable(int varnum, const TCHAR *var) 90 { 91 if (var != NULL && varnum >= 0 && varnum < __INST_LAST) 92 lstrcpy(g_variables + varnum*g_stringsize, var); 93 } 94 95 96 97 #endif//_EXDLL_H_