2 * Windows APIs that are different for each system.
3 * We use pointers to the entry points so that a
4 * single binary will run on all Windows systems.
9 Bacula® - The Network Backup Solution
11 Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
13 The main author of Bacula is Kern Sibbald, with contributions from
14 many others, a complete list can be found in the file AUTHORS.
15 This program is Free Software; you can redistribute it and/or
16 modify it under the terms of version two of the GNU General Public
17 License as published by the Free Software Foundation plus additions
18 that are listed in the file LICENSE.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 Bacula® is a registered trademark of John Walker.
31 The licensor of Bacula is the Free Software Foundation Europe
32 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33 Switzerland, email:ftf@fsfeurope.org.
38 // init with win9x, but maybe set to NT in InitWinAPI
39 DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
40 DWORD g_MinorVersion = 0;
44 t_OpenProcessToken p_OpenProcessToken = NULL;
45 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
46 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
48 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
50 t_CreateFileA p_CreateFileA = NULL;
51 t_CreateFileW p_CreateFileW = NULL;
52 t_CreateDirectoryA p_CreateDirectoryA;
53 t_CreateDirectoryW p_CreateDirectoryW;
55 t_wunlink p_wunlink = NULL;
56 t_wmkdir p_wmkdir = NULL;
58 t_GetFileAttributesA p_GetFileAttributesA = NULL;
59 t_GetFileAttributesW p_GetFileAttributesW = NULL;
61 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
62 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
64 t_SetFileAttributesA p_SetFileAttributesA = NULL;
65 t_SetFileAttributesW p_SetFileAttributesW = NULL;
66 t_BackupRead p_BackupRead = NULL;
67 t_BackupWrite p_BackupWrite = NULL;
68 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
69 t_MultiByteToWideChar p_MultiByteToWideChar = NULL;
71 t_AttachConsole p_AttachConsole = NULL;
73 t_FindFirstFileA p_FindFirstFileA = NULL;
74 t_FindFirstFileW p_FindFirstFileW = NULL;
76 t_FindNextFileA p_FindNextFileA = NULL;
77 t_FindNextFileW p_FindNextFileW = NULL;
79 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
80 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
82 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
83 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
85 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
86 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
88 t_SHGetFolderPath p_SHGetFolderPath = NULL;
93 OSVERSIONINFO osversioninfo = { sizeof(OSVERSIONINFO) };
95 // Get the current OS version
96 if (!GetVersionEx(&osversioninfo)) {
100 g_platform_id = osversioninfo.dwPlatformId;
101 g_MinorVersion = osversioninfo.dwMinorVersion;
104 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
106 /* create file calls */
107 p_CreateFileA = (t_CreateFileA)
108 GetProcAddress(hLib, "CreateFileA");
109 p_CreateDirectoryA = (t_CreateDirectoryA)
110 GetProcAddress(hLib, "CreateDirectoryA");
112 /* attribute calls */
113 p_GetFileAttributesA = (t_GetFileAttributesA)
114 GetProcAddress(hLib, "GetFileAttributesA");
115 p_GetFileAttributesExA = (t_GetFileAttributesExA)
116 GetProcAddress(hLib, "GetFileAttributesExA");
117 p_SetFileAttributesA = (t_SetFileAttributesA)
118 GetProcAddress(hLib, "SetFileAttributesA");
121 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
122 GetProcAddress(hLib, "SetProcessShutdownParameters");
124 /* char conversion calls */
125 p_WideCharToMultiByte = (t_WideCharToMultiByte)
126 GetProcAddress(hLib, "WideCharToMultiByte");
127 p_MultiByteToWideChar = (t_MultiByteToWideChar)
128 GetProcAddress(hLib, "MultiByteToWideChar");
131 p_FindFirstFileA = (t_FindFirstFileA)
132 GetProcAddress(hLib, "FindFirstFileA");
133 p_FindNextFileA = (t_FindNextFileA)
134 GetProcAddress(hLib, "FindNextFileA");
136 /* get and set directory */
137 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
138 GetProcAddress(hLib, "GetCurrentDirectoryA");
139 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
140 GetProcAddress(hLib, "SetCurrentDirectoryA");
142 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
143 p_CreateFileW = (t_CreateFileW)
144 GetProcAddress(hLib, "CreateFileW");
145 p_CreateDirectoryW = (t_CreateDirectoryW)
146 GetProcAddress(hLib, "CreateDirectoryW");
149 p_BackupRead = (t_BackupRead)
150 GetProcAddress(hLib, "BackupRead");
151 p_BackupWrite = (t_BackupWrite)
152 GetProcAddress(hLib, "BackupWrite");
154 p_GetFileAttributesW = (t_GetFileAttributesW)
155 GetProcAddress(hLib, "GetFileAttributesW");
156 p_GetFileAttributesExW = (t_GetFileAttributesExW)
157 GetProcAddress(hLib, "GetFileAttributesExW");
158 p_SetFileAttributesW = (t_SetFileAttributesW)
159 GetProcAddress(hLib, "SetFileAttributesW");
160 p_FindFirstFileW = (t_FindFirstFileW)
161 GetProcAddress(hLib, "FindFirstFileW");
162 p_FindNextFileW = (t_FindNextFileW)
163 GetProcAddress(hLib, "FindNextFileW");
164 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
165 GetProcAddress(hLib, "GetCurrentDirectoryW");
166 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
167 GetProcAddress(hLib, "SetCurrentDirectoryW");
169 /* some special stuff we need for VSS
170 but statically linkage doesn't work on Win 9x */
171 p_GetVolumePathNameW = (t_GetVolumePathNameW)
172 GetProcAddress(hLib, "GetVolumePathNameW");
173 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
174 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
176 p_AttachConsole = (t_AttachConsole)
177 GetProcAddress(hLib, "AttachConsole");
183 if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
184 hLib = LoadLibraryA("MSVCRT.DLL");
187 p_wunlink = (t_wunlink)
188 GetProcAddress(hLib, "_wunlink");
190 p_wmkdir = (t_wmkdir)
191 GetProcAddress(hLib, "_wmkdir");
196 hLib = LoadLibraryA("ADVAPI32.DLL");
198 p_OpenProcessToken = (t_OpenProcessToken)
199 GetProcAddress(hLib, "OpenProcessToken");
200 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
201 GetProcAddress(hLib, "AdjustTokenPrivileges");
202 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
203 GetProcAddress(hLib, "LookupPrivilegeValueA");
208 /* First try in SHFOLDER for older systems */
209 hLib = LoadLibraryA("SHFOLDER.DLL");
211 p_SHGetFolderPath = (t_SHGetFolderPath)
212 GetProcAddress(hLib, "SHGetFolderPath");
216 /* Now try Shell32.dll for newer systems */
217 hLib = LoadLibraryA("SHELL32.DLL");
219 p_SHGetFolderPath = (t_SHGetFolderPath)
220 GetProcAddress(hLib, "SHGetFolderPath");
224 atexit(Win32ConvCleanupCache);