]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/winapi.h
-- load cwprintf and cgetws dynamically via winapi
[bacula/bacula] / bacula / src / lib / winapi.h
1 /*
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.
5  *
6  *     Kern Sibbald MMIII
7  */
8 /*
9    Copyright (C) 2000-2005 Kern Sibbald
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
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 GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28 #ifndef __WINAPI_H
29 #define __WINAPI_H
30
31 #if defined(HAVE_WIN32)
32 /*
33  * Commented out native.h include statement, which is not distributed with the
34  * free version of VC++, and which is not used in bacula.
35  * 
36  * #if !defined(HAVE_MINGW) // native.h not present on mingw
37  * #include <native.h>
38  * #endif
39  */
40 #include <windef.h>
41 #endif
42
43 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
44
45 // unicode enabling of win 32 needs some defines and functions
46 #define MAX_PATH_UNICODE 32767
47 #define MAX_PATH_UTF8    MAX_PATH*3
48
49 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8);
50 int UTF8_2_wchar(WCHAR *pszUCS, const char *pszUTF, int cchWideChar = MAX_PATH);
51
52
53 /* In ADVAPI32.DLL */
54
55 typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
56 typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
57           PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
58 typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
59
60 extern t_OpenProcessToken      p_OpenProcessToken;
61 extern t_AdjustTokenPrivileges p_AdjustTokenPrivileges;
62 extern t_LookupPrivilegeValue  p_LookupPrivilegeValue;
63
64 /* In MSVCRT.DLL */
65 typedef int (__cdecl * t_wunlink) (const wchar_t *);
66 typedef int (__cdecl * t_wmkdir) (const wchar_t *);
67 typedef int (__cdecl * t_wopen)  (const wchar_t *, int, ...);
68
69 typedef wchar_t* (__cdecl *t_cgetws) (wchar_t *);
70 typedef int      (__cdecl *t_cwprintf) (const wchar_t *, ...);
71
72 extern t_wunlink   p_wunlink;
73 extern t_wmkdir    p_wmkdir;
74 extern t_wopen     p_wopen;
75
76 extern t_cgetws    p_cgetws;
77 extern t_cwprintf  p_cwprintf;
78 /* In KERNEL32.DLL */
79 typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS,
80        LPVOID);
81 typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS,
82        LPVOID);
83
84 typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR);
85 typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR);
86 typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD);
87 typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD);
88
89 typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
90         DWORD , DWORD, HANDLE);
91 typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
92         DWORD , DWORD, HANDLE);
93
94 typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
95 typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
96 typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
97
98 typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int,
99                                               LPSTR, int, LPCSTR, LPBOOL);
100
101 typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int);
102 typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA);
103 typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW);
104
105 typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA);
106 typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW);
107
108 typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR);
109 typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR);
110
111 typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR);
112 typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR);
113
114 extern t_GetFileAttributesA   p_GetFileAttributesA;
115 extern t_GetFileAttributesW   p_GetFileAttributesW;
116
117 extern t_GetFileAttributesExA   p_GetFileAttributesExA;
118 extern t_GetFileAttributesExW   p_GetFileAttributesExW;
119
120 extern t_SetFileAttributesA   p_SetFileAttributesA;
121 extern t_SetFileAttributesW   p_SetFileAttributesW;
122
123 extern t_CreateFileA   p_CreateFileA;
124 extern t_CreateFileW   p_CreateFileW;
125 extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters;
126 extern t_BackupRead         p_BackupRead;
127 extern t_BackupWrite        p_BackupWrite;
128
129 extern t_WideCharToMultiByte p_WideCharToMultiByte;
130 extern t_MultiByteToWideChar p_MultiByteToWideChar;
131
132 extern t_FindFirstFileA p_FindFirstFileA;
133 extern t_FindFirstFileW p_FindFirstFileW;
134
135 extern t_FindNextFileA p_FindNextFileA;
136 extern t_FindNextFileW p_FindNextFileW;
137
138 extern t_SetCurrentDirectoryA p_SetCurrentDirectoryA;
139 extern t_SetCurrentDirectoryW p_SetCurrentDirectoryW;
140
141 extern t_GetCurrentDirectoryA p_GetCurrentDirectoryA;
142 extern t_GetCurrentDirectoryW p_GetCurrentDirectoryW;
143
144 #ifdef WIN32_VSS
145 class VSSClient;
146 extern VSSClient g_VSSClient;
147 #endif
148
149 void InitWinAPIWrapper();
150 #endif
151
152 #endif /* __WINAPI_H */