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.
26 #if defined(HAVE_WIN32)
28 * Commented out native.h include statement, which is not distributed with the
29 * free version of VC++, and which is not used in bacula.
31 * #if !defined(HAVE_MINGW) // native.h not present on mingw
41 // unicode enabling of win 32 needs some defines and functions
43 // using an average of 3 bytes per character is probably fine in
44 // practice but I believe that Windows actually uses UTF-16 encoding
45 // as opposed to UCS2 which means characters 0x10000-0x10ffff are
46 // valid and result in 4 byte UTF-8 encodings.
47 #define MAX_PATH_UTF8 MAX_PATH*4 // strict upper bound on UTF-16 to UTF-8 conversion
49 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileattributesex.asp
50 // In the ANSI version of this function, the name is limited to
51 // MAX_PATH characters. To extend this limit to 32,767 wide
52 // characters, call the Unicode version of the function and prepend
53 // "\\?\" to the path. For more information, see Naming a File.
54 #define MAX_PATH_W 32767
56 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8);
57 int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF);
58 int make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath = NULL);
60 // init with win9x, but maybe set to NT in InitWinAPI
61 extern DWORD DLL_IMP_EXP g_platform_id;
62 extern DWORD DLL_IMP_EXP g_MinorVersion;
66 typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
67 typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
68 PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
69 typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
71 extern t_OpenProcessToken DLL_IMP_EXP p_OpenProcessToken;
72 extern t_AdjustTokenPrivileges DLL_IMP_EXP p_AdjustTokenPrivileges;
73 extern t_LookupPrivilegeValue DLL_IMP_EXP p_LookupPrivilegeValue;
76 typedef int (__cdecl * t_wunlink) (const wchar_t *);
77 typedef int (__cdecl * t_wmkdir) (const wchar_t *);
78 typedef int (__cdecl * t_wopen) (const wchar_t *, int, ...);
80 extern t_wunlink DLL_IMP_EXP p_wunlink;
81 extern t_wmkdir DLL_IMP_EXP p_wmkdir;
84 typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS,
86 typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS,
89 typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR);
90 typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR);
91 typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD);
92 typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD);
94 typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
95 DWORD , DWORD, HANDLE);
96 typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
97 DWORD , DWORD, HANDLE);
99 typedef BOOL (WINAPI * t_CreateDirectoryA) (LPCSTR, LPSECURITY_ATTRIBUTES);
100 typedef BOOL (WINAPI * t_CreateDirectoryW) (LPCWSTR, LPSECURITY_ATTRIBUTES);
102 typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
103 typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
104 typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
106 typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int,
107 LPSTR, int, LPCSTR, LPBOOL);
109 typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int);
110 typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA);
111 typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW);
113 typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA);
114 typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW);
116 typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR);
117 typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR);
119 typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR);
120 typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR);
122 typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD);
123 typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD);
125 typedef BOOL (WINAPI * t_AttachConsole) (DWORD);
127 extern t_GetFileAttributesA DLL_IMP_EXP p_GetFileAttributesA;
128 extern t_GetFileAttributesW DLL_IMP_EXP p_GetFileAttributesW;
130 extern t_GetFileAttributesExA DLL_IMP_EXP p_GetFileAttributesExA;
131 extern t_GetFileAttributesExW DLL_IMP_EXP p_GetFileAttributesExW;
133 extern t_SetFileAttributesA DLL_IMP_EXP p_SetFileAttributesA;
134 extern t_SetFileAttributesW DLL_IMP_EXP p_SetFileAttributesW;
136 extern t_CreateFileA DLL_IMP_EXP p_CreateFileA;
137 extern t_CreateFileW DLL_IMP_EXP p_CreateFileW;
139 extern t_CreateDirectoryA DLL_IMP_EXP p_CreateDirectoryA;
140 extern t_CreateDirectoryW DLL_IMP_EXP p_CreateDirectoryW;
142 extern t_SetProcessShutdownParameters DLL_IMP_EXP p_SetProcessShutdownParameters;
143 extern t_BackupRead DLL_IMP_EXP p_BackupRead;
144 extern t_BackupWrite DLL_IMP_EXP p_BackupWrite;
146 extern t_WideCharToMultiByte DLL_IMP_EXP p_WideCharToMultiByte;
147 extern t_MultiByteToWideChar DLL_IMP_EXP p_MultiByteToWideChar;
149 extern t_FindFirstFileA DLL_IMP_EXP p_FindFirstFileA;
150 extern t_FindFirstFileW DLL_IMP_EXP p_FindFirstFileW;
152 extern t_FindNextFileA DLL_IMP_EXP p_FindNextFileA;
153 extern t_FindNextFileW DLL_IMP_EXP p_FindNextFileW;
155 extern t_SetCurrentDirectoryA DLL_IMP_EXP p_SetCurrentDirectoryA;
156 extern t_SetCurrentDirectoryW DLL_IMP_EXP p_SetCurrentDirectoryW;
158 extern t_GetCurrentDirectoryA DLL_IMP_EXP p_GetCurrentDirectoryA;
159 extern t_GetCurrentDirectoryW DLL_IMP_EXP p_GetCurrentDirectoryW;
161 extern t_GetVolumePathNameW DLL_IMP_EXP p_GetVolumePathNameW;
162 extern t_GetVolumeNameForVolumeMountPointW DLL_IMP_EXP p_GetVolumeNameForVolumeMountPointW;
164 extern t_AttachConsole DLL_IMP_EXP p_AttachConsole;
166 void InitWinAPIWrapper();
169 #endif /* __WINAPI_H */