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 Copyright (C) 2003-2006 Kern Sibbald
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as amended with additional clauses defined in the
14 file LICENSE in the main source directory.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 the file LICENSE for additional details.
29 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
39 // init with win9x, but maybe set to NT in InitWinAPI
40 DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
42 /* preset VSSClient to NULL */
43 VSSClient *g_pVSSClient = NULL;
49 t_OpenProcessToken p_OpenProcessToken = NULL;
50 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
51 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
53 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
55 t_CreateFileA p_CreateFileA = NULL;
56 t_CreateFileW p_CreateFileW = NULL;
57 t_CreateDirectoryA p_CreateDirectoryA;
58 t_CreateDirectoryW p_CreateDirectoryW;
60 t_wunlink p_wunlink = NULL;
61 t_wmkdir p_wmkdir = NULL;
62 t_wopen p_wopen = NULL;
64 t_GetFileAttributesA p_GetFileAttributesA = NULL;
65 t_GetFileAttributesW p_GetFileAttributesW = NULL;
67 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
68 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
70 t_SetFileAttributesA p_SetFileAttributesA = NULL;
71 t_SetFileAttributesW p_SetFileAttributesW = NULL;
72 t_BackupRead p_BackupRead = NULL;
73 t_BackupWrite p_BackupWrite = NULL;
74 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
75 t_MultiByteToWideChar p_MultiByteToWideChar = NULL;
77 t_FindFirstFileA p_FindFirstFileA = NULL;
78 t_FindFirstFileW p_FindFirstFileW = NULL;
80 t_FindNextFileA p_FindNextFileA = NULL;
81 t_FindNextFileW p_FindNextFileW = NULL;
83 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
84 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
86 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
87 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
89 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
90 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
97 delete (g_pVSSClient);
104 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
106 /* create file calls */
107 p_CreateFileA = (t_CreateFileA)
108 GetProcAddress(hLib, "CreateFileA");
109 p_CreateFileW = (t_CreateFileW)
110 GetProcAddress(hLib, "CreateFileW");
112 p_CreateDirectoryA = (t_CreateDirectoryA)
113 GetProcAddress(hLib, "CreateDirectoryA");
114 p_CreateDirectoryW = (t_CreateDirectoryW)
115 GetProcAddress(hLib, "CreateDirectoryW");
117 /* attribute calls */
118 p_GetFileAttributesA = (t_GetFileAttributesA)
119 GetProcAddress(hLib, "GetFileAttributesA");
120 p_GetFileAttributesW = (t_GetFileAttributesW)
121 GetProcAddress(hLib, "GetFileAttributesW");
122 p_GetFileAttributesExA = (t_GetFileAttributesExA)
123 GetProcAddress(hLib, "GetFileAttributesExA");
124 p_GetFileAttributesExW = (t_GetFileAttributesExW)
125 GetProcAddress(hLib, "GetFileAttributesExW");
126 p_SetFileAttributesA = (t_SetFileAttributesA)
127 GetProcAddress(hLib, "SetFileAttributesA");
128 p_SetFileAttributesW = (t_SetFileAttributesW)
129 GetProcAddress(hLib, "SetFileAttributesW");
131 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
132 GetProcAddress(hLib, "SetProcessShutdownParameters");
134 p_BackupRead = (t_BackupRead)
135 GetProcAddress(hLib, "BackupRead");
136 p_BackupWrite = (t_BackupWrite)
137 GetProcAddress(hLib, "BackupWrite");
138 /* char conversion calls */
139 p_WideCharToMultiByte = (t_WideCharToMultiByte)
140 GetProcAddress(hLib, "WideCharToMultiByte");
141 p_MultiByteToWideChar = (t_MultiByteToWideChar)
142 GetProcAddress(hLib, "MultiByteToWideChar");
145 p_FindFirstFileA = (t_FindFirstFileA)
146 GetProcAddress(hLib, "FindFirstFileA");
147 p_FindFirstFileW = (t_FindFirstFileW)
148 GetProcAddress(hLib, "FindFirstFileW");
149 p_FindNextFileA = (t_FindNextFileA)
150 GetProcAddress(hLib, "FindNextFileA");
151 p_FindNextFileW = (t_FindNextFileW)
152 GetProcAddress(hLib, "FindNextFileW");
153 /* set and get directory */
154 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
155 GetProcAddress(hLib, "SetCurrentDirectoryA");
156 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
157 GetProcAddress(hLib, "SetCurrentDirectoryW");
158 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
159 GetProcAddress(hLib, "GetCurrentDirectoryA");
160 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
161 GetProcAddress(hLib, "GetCurrentDirectoryW");
163 /* some special stuff we need for VSS
164 but statically linkage doesn't work on Win 9x */
165 p_GetVolumePathNameW = (t_GetVolumePathNameW)
166 GetProcAddress(hLib, "GetVolumePathNameW");
167 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
168 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
173 hLib = LoadLibraryA("MSVCRT.DLL");
176 p_wunlink = (t_wunlink)
177 GetProcAddress(hLib, "_wunlink");
179 p_wmkdir = (t_wmkdir)
180 GetProcAddress(hLib, "_wmkdir");
183 GetProcAddress(hLib, "_wopen");
188 hLib = LoadLibraryA("ADVAPI32.DLL");
190 p_OpenProcessToken = (t_OpenProcessToken)
191 GetProcAddress(hLib, "OpenProcessToken");
192 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
193 GetProcAddress(hLib, "AdjustTokenPrivileges");
194 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
195 GetProcAddress(hLib, "LookupPrivilegeValueA");
199 // do we run on win 9x ???
200 OSVERSIONINFO osversioninfo;
201 osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
203 DWORD dwMinorVersion;
205 // Get the current OS version
206 if (!GetVersionEx(&osversioninfo)) {
210 g_platform_id = osversioninfo.dwPlatformId;
211 dwMinorVersion = osversioninfo.dwMinorVersion;
214 /* deinitialize some routines on win95 - they're not implemented well */
215 if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) {
217 p_BackupWrite = NULL;
219 p_CreateFileW = NULL;
220 p_GetFileAttributesW = NULL;
221 p_GetFileAttributesExW = NULL;
223 p_SetFileAttributesW = NULL;
225 p_FindFirstFileW = NULL;
226 p_FindNextFileW = NULL;
227 p_SetCurrentDirectoryW = NULL;
228 p_GetCurrentDirectoryW = NULL;
234 p_GetVolumePathNameW = NULL;
235 p_GetVolumeNameForVolumeMountPointW = NULL;
238 /* decide which vss class to initialize */
240 switch (dwMinorVersion) {
242 g_pVSSClient = new VSSClientXP();
246 g_pVSSClient = new VSSClient2003();
250 #endif /* WIN32_VSS */
251 atexit(Win32ConvCleanupCache);
257 int win32_client = 0;