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.
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;
51 t_CreateDirectoryA p_CreateDirectoryA;
52 t_CreateDirectoryW p_CreateDirectoryW;
54 t_wunlink p_wunlink = NULL;
55 t_wmkdir p_wmkdir = NULL;
56 t_wopen p_wopen = 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_FindFirstFileA p_FindFirstFileA = NULL;
72 t_FindFirstFileW p_FindFirstFileW = NULL;
74 t_FindNextFileA p_FindNextFileA = NULL;
75 t_FindNextFileW p_FindNextFileW = NULL;
77 t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL;
78 t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
80 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
81 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
83 t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
84 t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
91 delete (g_pVSSClient);
98 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
100 /* create file calls */
101 p_CreateFileA = (t_CreateFileA)
102 GetProcAddress(hLib, "CreateFileA");
103 p_CreateFileW = (t_CreateFileW)
104 GetProcAddress(hLib, "CreateFileW");
106 p_CreateDirectoryA = (t_CreateDirectoryA)
107 GetProcAddress(hLib, "CreateDirectoryA");
108 p_CreateDirectoryW = (t_CreateDirectoryW)
109 GetProcAddress(hLib, "CreateDirectoryW");
111 /* attribute calls */
112 p_GetFileAttributesA = (t_GetFileAttributesA)
113 GetProcAddress(hLib, "GetFileAttributesA");
114 p_GetFileAttributesW = (t_GetFileAttributesW)
115 GetProcAddress(hLib, "GetFileAttributesW");
116 p_GetFileAttributesExA = (t_GetFileAttributesExA)
117 GetProcAddress(hLib, "GetFileAttributesExA");
118 p_GetFileAttributesExW = (t_GetFileAttributesExW)
119 GetProcAddress(hLib, "GetFileAttributesExW");
120 p_SetFileAttributesA = (t_SetFileAttributesA)
121 GetProcAddress(hLib, "SetFileAttributesA");
122 p_SetFileAttributesW = (t_SetFileAttributesW)
123 GetProcAddress(hLib, "SetFileAttributesW");
125 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
126 GetProcAddress(hLib, "SetProcessShutdownParameters");
128 p_BackupRead = (t_BackupRead)
129 GetProcAddress(hLib, "BackupRead");
130 p_BackupWrite = (t_BackupWrite)
131 GetProcAddress(hLib, "BackupWrite");
132 /* char conversion calls */
133 p_WideCharToMultiByte = (t_WideCharToMultiByte)
134 GetProcAddress(hLib, "WideCharToMultiByte");
135 p_MultiByteToWideChar = (t_MultiByteToWideChar)
136 GetProcAddress(hLib, "MultiByteToWideChar");
139 p_FindFirstFileA = (t_FindFirstFileA)
140 GetProcAddress(hLib, "FindFirstFileA");
141 p_FindFirstFileW = (t_FindFirstFileW)
142 GetProcAddress(hLib, "FindFirstFileW");
143 p_FindNextFileA = (t_FindNextFileA)
144 GetProcAddress(hLib, "FindNextFileA");
145 p_FindNextFileW = (t_FindNextFileW)
146 GetProcAddress(hLib, "FindNextFileW");
147 /* set and get directory */
148 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
149 GetProcAddress(hLib, "SetCurrentDirectoryA");
150 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
151 GetProcAddress(hLib, "SetCurrentDirectoryW");
152 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
153 GetProcAddress(hLib, "GetCurrentDirectoryA");
154 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
155 GetProcAddress(hLib, "GetCurrentDirectoryW");
157 /* some special stuff we need for VSS
158 but statically linkage doesn't work on Win 9x */
159 p_GetVolumePathNameW = (t_GetVolumePathNameW)
160 GetProcAddress(hLib, "GetVolumePathNameW");
161 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
162 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
167 hLib = LoadLibraryA("MSVCRT.DLL");
170 p_wunlink = (t_wunlink)
171 GetProcAddress(hLib, "_wunlink");
173 p_wmkdir = (t_wmkdir)
174 GetProcAddress(hLib, "_wmkdir");
177 GetProcAddress(hLib, "_wopen");
182 hLib = LoadLibraryA("ADVAPI32.DLL");
184 p_OpenProcessToken = (t_OpenProcessToken)
185 GetProcAddress(hLib, "OpenProcessToken");
186 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
187 GetProcAddress(hLib, "AdjustTokenPrivileges");
188 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
189 GetProcAddress(hLib, "LookupPrivilegeValueA");
193 // do we run on win 9x ???
194 OSVERSIONINFO osversioninfo;
195 osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
197 DWORD dwMinorVersion;
199 // Get the current OS version
200 if (!GetVersionEx(&osversioninfo)) {
204 g_platform_id = osversioninfo.dwPlatformId;
205 dwMinorVersion = osversioninfo.dwMinorVersion;
208 /* deinitialize some routines on win95 - they're not implemented well */
209 if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) {
211 p_BackupWrite = NULL;
213 p_CreateFileW = NULL;
214 p_GetFileAttributesW = NULL;
215 p_GetFileAttributesExW = NULL;
217 p_SetFileAttributesW = NULL;
219 p_FindFirstFileW = NULL;
220 p_FindNextFileW = NULL;
221 p_SetCurrentDirectoryW = NULL;
222 p_GetCurrentDirectoryW = NULL;
228 p_GetVolumePathNameW = NULL;
229 p_GetVolumeNameForVolumeMountPointW = NULL;
232 /* decide which vss class to initialize */
234 switch (dwMinorVersion) {
236 g_pVSSClient = new VSSClientXP();
240 g_pVSSClient = new VSSClient2003();
244 #endif /* WIN32_VSS */