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-2005 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.
25 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
33 // init with win9x, but maybe set to NT in InitWinAPI
34 DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
36 /* preset VSSClient to NULL */
37 VSSClient *g_pVSSClient = NULL;
43 t_OpenProcessToken p_OpenProcessToken = NULL;
44 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
45 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
47 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
49 t_CreateFileA p_CreateFileA = NULL;
50 t_CreateFileW p_CreateFileW = NULL;
52 t_wunlink p_wunlink = NULL;
53 t_wmkdir p_wmkdir = NULL;
54 t_wopen p_wopen = NULL;
56 t_GetFileAttributesA p_GetFileAttributesA = NULL;
57 t_GetFileAttributesW p_GetFileAttributesW = NULL;
59 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
60 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
62 t_SetFileAttributesA p_SetFileAttributesA = NULL;
63 t_SetFileAttributesW p_SetFileAttributesW = NULL;
64 t_BackupRead p_BackupRead = NULL;
65 t_BackupWrite p_BackupWrite = NULL;
66 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
67 t_MultiByteToWideChar p_MultiByteToWideChar = NULL;
69 t_FindFirstFileA p_FindFirstFileA = NULL;
70 t_FindFirstFileW p_FindFirstFileW = NULL;
72 t_FindNextFileA p_FindNextFileA = NULL;
73 t_FindNextFileW p_FindNextFileW = NULL;
75 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
76 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
78 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
79 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
81 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
82 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
89 delete (g_pVSSClient);
96 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
98 /* create file calls */
99 p_CreateFileA = (t_CreateFileA)
100 GetProcAddress(hLib, "CreateFileA");
101 p_CreateFileW = (t_CreateFileW)
102 GetProcAddress(hLib, "CreateFileW");
104 /* attribute calls */
105 p_GetFileAttributesA = (t_GetFileAttributesA)
106 GetProcAddress(hLib, "GetFileAttributesA");
107 p_GetFileAttributesW = (t_GetFileAttributesW)
108 GetProcAddress(hLib, "GetFileAttributesW");
109 p_GetFileAttributesExA = (t_GetFileAttributesExA)
110 GetProcAddress(hLib, "GetFileAttributesExA");
111 p_GetFileAttributesExW = (t_GetFileAttributesExW)
112 GetProcAddress(hLib, "GetFileAttributesExW");
113 p_SetFileAttributesA = (t_SetFileAttributesA)
114 GetProcAddress(hLib, "SetFileAttributesA");
115 p_SetFileAttributesW = (t_SetFileAttributesW)
116 GetProcAddress(hLib, "SetFileAttributesW");
118 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
119 GetProcAddress(hLib, "SetProcessShutdownParameters");
121 p_BackupRead = (t_BackupRead)
122 GetProcAddress(hLib, "BackupRead");
123 p_BackupWrite = (t_BackupWrite)
124 GetProcAddress(hLib, "BackupWrite");
125 /* char conversion calls */
126 p_WideCharToMultiByte = (t_WideCharToMultiByte)
127 GetProcAddress(hLib, "WideCharToMultiByte");
128 p_MultiByteToWideChar = (t_MultiByteToWideChar)
129 GetProcAddress(hLib, "MultiByteToWideChar");
132 p_FindFirstFileA = (t_FindFirstFileA)
133 GetProcAddress(hLib, "FindFirstFileA");
134 p_FindFirstFileW = (t_FindFirstFileW)
135 GetProcAddress(hLib, "FindFirstFileW");
136 p_FindNextFileA = (t_FindNextFileA)
137 GetProcAddress(hLib, "FindNextFileA");
138 p_FindNextFileW = (t_FindNextFileW)
139 GetProcAddress(hLib, "FindNextFileW");
140 /* set and get directory */
141 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
142 GetProcAddress(hLib, "SetCurrentDirectoryA");
143 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
144 GetProcAddress(hLib, "SetCurrentDirectoryW");
145 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
146 GetProcAddress(hLib, "GetCurrentDirectoryA");
147 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
148 GetProcAddress(hLib, "GetCurrentDirectoryW");
150 /* some special stuff we need for VSS
151 but statically linkage doesn't work on Win 9x */
152 p_GetVolumePathNameW = (t_GetVolumePathNameW)
153 GetProcAddress(hLib, "GetVolumePathNameW");
154 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
155 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
160 hLib = LoadLibraryA("MSVCRT.DLL");
163 p_wunlink = (t_wunlink)
164 GetProcAddress(hLib, "_wunlink");
166 p_wmkdir = (t_wmkdir)
167 GetProcAddress(hLib, "_wmkdir");
170 GetProcAddress(hLib, "_wopen");
175 hLib = LoadLibraryA("ADVAPI32.DLL");
177 p_OpenProcessToken = (t_OpenProcessToken)
178 GetProcAddress(hLib, "OpenProcessToken");
179 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
180 GetProcAddress(hLib, "AdjustTokenPrivileges");
181 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
182 GetProcAddress(hLib, "LookupPrivilegeValueA");
186 // do we run on win 9x ???
187 OSVERSIONINFO osversioninfo;
188 osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
190 DWORD dwMinorVersion;
192 // Get the current OS version
193 if (!GetVersionEx(&osversioninfo)) {
197 g_platform_id = osversioninfo.dwPlatformId;
198 dwMinorVersion = osversioninfo.dwMinorVersion;
201 /* deinitialize some routines on win95 - they're not implemented well */
202 if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) {
204 p_BackupWrite = NULL;
206 p_CreateFileW = NULL;
207 p_GetFileAttributesW = NULL;
208 p_GetFileAttributesExW = NULL;
210 p_SetFileAttributesW = NULL;
212 p_FindFirstFileW = NULL;
213 p_FindNextFileW = NULL;
214 p_SetCurrentDirectoryW = NULL;
215 p_GetCurrentDirectoryW = NULL;
221 p_GetVolumePathNameW = NULL;
222 p_GetVolumeNameForVolumeMountPointW = NULL;
225 /* decide which vss class to initialize */
227 switch (dwMinorVersion) {
229 g_pVSSClient = new VSSClientXP();
233 g_pVSSClient = new VSSClient2003();
237 #endif /* WIN32_VSS */