VirtualBox

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

Last change on this file since 76540 was 76540, checked in by vboxsync, 6 years ago

Additions/WINNT: scm --fix-header-guards. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 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 _EXDLL_H_
22#define _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
43typedef 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
49static unsigned int g_stringsize;
50static stack_t **g_stacktop;
51static char *g_variables;
52
53static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack
54static void __stdcall pushstring(const char *str) UNUSED;
55static char * __stdcall getuservariable(const int varnum) UNUSED;
56static void __stdcall setuservariable(const int varnum, const char *var) UNUSED;
57
58enum
59{
60INST_0, // $0
61INST_1, // $1
62INST_2, // $2
63INST_3, // $3
64INST_4, // $4
65INST_5, // $5
66INST_6, // $6
67INST_7, // $7
68INST_8, // $8
69INST_9, // $9
70INST_R0, // $R0
71INST_R1, // $R1
72INST_R2, // $R2
73INST_R3, // $R3
74INST_R4, // $R4
75INST_R5, // $R5
76INST_R6, // $R6
77INST_R7, // $R7
78INST_R8, // $R8
79INST_R9, // $R9
80INST_CMDLINE, // $CMDLINE
81INST_INSTDIR, // $INSTDIR
82INST_OUTDIR, // $OUTDIR
83INST_EXEDIR, // $EXEDIR
84INST_LANG, // $LANGUAGE
85__INST_LAST
86};
87
88// utility functions (not required but often useful)
89static 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
101static 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
112static 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
119static 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//_EXDLL_H_
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette