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)
35 // init with win9x, but maybe set to NT in InitWinAPI
36 DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
38 /* preset VSSClient to NULL */
39 VSSClient *g_pVSSClient = NULL;
45 t_OpenProcessToken p_OpenProcessToken = NULL;
46 t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL;
47 t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL;
49 t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL;
51 t_CreateFileA p_CreateFileA = NULL;
52 t_CreateFileW p_CreateFileW = NULL;
53 t_CreateDirectoryA p_CreateDirectoryA;
54 t_CreateDirectoryW p_CreateDirectoryW;
56 t_wunlink p_wunlink = NULL;
57 t_wmkdir p_wmkdir = NULL;
58 t_wopen p_wopen = NULL;
60 t_GetFileAttributesA p_GetFileAttributesA = NULL;
61 t_GetFileAttributesW p_GetFileAttributesW = NULL;
63 t_GetFileAttributesExA p_GetFileAttributesExA = NULL;
64 t_GetFileAttributesExW p_GetFileAttributesExW = NULL;
66 t_SetFileAttributesA p_SetFileAttributesA = NULL;
67 t_SetFileAttributesW p_SetFileAttributesW = NULL;
68 t_BackupRead p_BackupRead = NULL;
69 t_BackupWrite p_BackupWrite = NULL;
70 t_WideCharToMultiByte p_WideCharToMultiByte = NULL;
71 t_MultiByteToWideChar p_MultiByteToWideChar = 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;
93 delete (g_pVSSClient);
100 HMODULE hLib = LoadLibraryA("KERNEL32.DLL");
102 /* create file calls */
103 p_CreateFileA = (t_CreateFileA)
104 GetProcAddress(hLib, "CreateFileA");
105 p_CreateFileW = (t_CreateFileW)
106 GetProcAddress(hLib, "CreateFileW");
108 p_CreateDirectoryA = (t_CreateDirectoryA)
109 GetProcAddress(hLib, "CreateDirectoryA");
110 p_CreateDirectoryW = (t_CreateDirectoryW)
111 GetProcAddress(hLib, "CreateDirectoryW");
113 /* attribute calls */
114 p_GetFileAttributesA = (t_GetFileAttributesA)
115 GetProcAddress(hLib, "GetFileAttributesA");
116 p_GetFileAttributesW = (t_GetFileAttributesW)
117 GetProcAddress(hLib, "GetFileAttributesW");
118 p_GetFileAttributesExA = (t_GetFileAttributesExA)
119 GetProcAddress(hLib, "GetFileAttributesExA");
120 p_GetFileAttributesExW = (t_GetFileAttributesExW)
121 GetProcAddress(hLib, "GetFileAttributesExW");
122 p_SetFileAttributesA = (t_SetFileAttributesA)
123 GetProcAddress(hLib, "SetFileAttributesA");
124 p_SetFileAttributesW = (t_SetFileAttributesW)
125 GetProcAddress(hLib, "SetFileAttributesW");
127 p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters)
128 GetProcAddress(hLib, "SetProcessShutdownParameters");
130 p_BackupRead = (t_BackupRead)
131 GetProcAddress(hLib, "BackupRead");
132 p_BackupWrite = (t_BackupWrite)
133 GetProcAddress(hLib, "BackupWrite");
134 /* char conversion calls */
135 p_WideCharToMultiByte = (t_WideCharToMultiByte)
136 GetProcAddress(hLib, "WideCharToMultiByte");
137 p_MultiByteToWideChar = (t_MultiByteToWideChar)
138 GetProcAddress(hLib, "MultiByteToWideChar");
141 p_FindFirstFileA = (t_FindFirstFileA)
142 GetProcAddress(hLib, "FindFirstFileA");
143 p_FindFirstFileW = (t_FindFirstFileW)
144 GetProcAddress(hLib, "FindFirstFileW");
145 p_FindNextFileA = (t_FindNextFileA)
146 GetProcAddress(hLib, "FindNextFileA");
147 p_FindNextFileW = (t_FindNextFileW)
148 GetProcAddress(hLib, "FindNextFileW");
149 /* set and get directory */
150 p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA)
151 GetProcAddress(hLib, "SetCurrentDirectoryA");
152 p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW)
153 GetProcAddress(hLib, "SetCurrentDirectoryW");
154 p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA)
155 GetProcAddress(hLib, "GetCurrentDirectoryA");
156 p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
157 GetProcAddress(hLib, "GetCurrentDirectoryW");
159 /* some special stuff we need for VSS
160 but statically linkage doesn't work on Win 9x */
161 p_GetVolumePathNameW = (t_GetVolumePathNameW)
162 GetProcAddress(hLib, "GetVolumePathNameW");
163 p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
164 GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
169 hLib = LoadLibraryA("MSVCRT.DLL");
172 p_wunlink = (t_wunlink)
173 GetProcAddress(hLib, "_wunlink");
175 p_wmkdir = (t_wmkdir)
176 GetProcAddress(hLib, "_wmkdir");
179 GetProcAddress(hLib, "_wopen");
184 hLib = LoadLibraryA("ADVAPI32.DLL");
186 p_OpenProcessToken = (t_OpenProcessToken)
187 GetProcAddress(hLib, "OpenProcessToken");
188 p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges)
189 GetProcAddress(hLib, "AdjustTokenPrivileges");
190 p_LookupPrivilegeValue = (t_LookupPrivilegeValue)
191 GetProcAddress(hLib, "LookupPrivilegeValueA");
195 // do we run on win 9x ???
196 OSVERSIONINFO osversioninfo;
197 osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
199 DWORD dwMinorVersion;
201 // Get the current OS version
202 if (!GetVersionEx(&osversioninfo)) {
206 g_platform_id = osversioninfo.dwPlatformId;
207 dwMinorVersion = osversioninfo.dwMinorVersion;
210 /* deinitialize some routines on win95 - they're not implemented well */
211 if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) {
213 p_BackupWrite = NULL;
215 p_CreateFileW = NULL;
216 p_GetFileAttributesW = NULL;
217 p_GetFileAttributesExW = NULL;
219 p_SetFileAttributesW = NULL;
221 p_FindFirstFileW = NULL;
222 p_FindNextFileW = NULL;
223 p_SetCurrentDirectoryW = NULL;
224 p_GetCurrentDirectoryW = NULL;
230 p_GetVolumePathNameW = NULL;
231 p_GetVolumeNameForVolumeMountPointW = NULL;
234 /* decide which vss class to initialize */
236 switch (dwMinorVersion) {
238 g_pVSSClient = new VSSClientXP();
242 g_pVSSClient = new VSSClient2003();
246 #endif /* WIN32_VSS */
252 int win32_client = 0;