Rev 532 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
268 | daniel-mar | 2 | This file is part of a common library |
536 | daniel-mar | 3 | Copyright (C) 2002-2006 Toby Thain, toby@telegraphics.net |
259 | daniel-mar | 4 | |
5 | This program is free software; you can redistribute it and/or modify |
||
6 | it under the terms of the GNU General Public License as published by |
||
7 | the Free Software Foundation; either version 2 of the License, or |
||
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU General Public License |
||
16 | along with this program; if not, write to the Free Software |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | #include <windows.h> |
||
463 | daniel-mar | 21 | #include <stdio.h> |
259 | daniel-mar | 22 | |
23 | #include "compat_win.h" |
||
402 | daniel-mar | 24 | #include "compat_win_resource.h" |
259 | daniel-mar | 25 | |
411 | daniel-mar | 26 | typedef BOOL(__stdcall* f_GetVersionEx)(LPOSVERSIONINFOA lpVersionInformation); |
532 | daniel-mar | 27 | Boolean Implements3264ResourceAPI(void) { |
311 | daniel-mar | 28 | #ifdef _WIN64 |
29 | // 64 bit OS is never Win9x, so it must be WinNT |
||
30 | return true; |
||
31 | #else |
||
411 | daniel-mar | 32 | HMODULE hLib; |
33 | f_GetVersionEx fGetVersionEx; |
||
34 | BOOL res; |
||
35 | |||
444 | daniel-mar | 36 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
411 | daniel-mar | 37 | if (!hLib) return 0; |
38 | fGetVersionEx = (f_GetVersionEx)(void*)GetProcAddress(hLib, "GetVersionExA"); |
||
39 | if (fGetVersionEx != 0) { |
||
444 | daniel-mar | 40 | OSVERSIONINFOA osv; |
41 | osv.dwOSVersionInfoSize = sizeof(osv); |
||
411 | daniel-mar | 42 | res = fGetVersionEx(&osv); |
43 | FreeLibrary(hLib); |
||
414 | daniel-mar | 44 | // Windows NT 3.51 does implement GetVersionExA() and UpdateResourceA(), but it doesn't know about 64 bit images. |
411 | daniel-mar | 45 | // Windows NT 4.0 does implement UpdateResourceA(), and it can handle 64 bit images |
46 | return res && osv.dwMajorVersion >= 4 && osv.dwPlatformId == VER_PLATFORM_WIN32_NT; |
||
47 | } |
||
48 | else { |
||
414 | daniel-mar | 49 | // Windows NT 3.1 doesn't have GetVersionExA(), doesn't implement UpdateResourceA(), and doesn't know about 64 bit images |
50 | // Therefore, we conclude that if GetVersionExA() is missing, then we are on a system that requires manual resource processing |
||
411 | daniel-mar | 51 | FreeLibrary(hLib); |
52 | return false; |
||
53 | } |
||
311 | daniel-mar | 54 | #endif |
259 | daniel-mar | 55 | } |
56 | |||
57 | // --------------------------------- |
||
58 | |||
59 | typedef ULONGLONG(__stdcall* f_GetTickCount64)(); |
||
532 | daniel-mar | 60 | ULONGLONG _GetTickCount64(void) { |
259 | daniel-mar | 61 | HMODULE hLib; |
62 | f_GetTickCount64 fGetTickCount64; |
||
63 | ULONGLONG res; |
||
64 | |||
444 | daniel-mar | 65 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
259 | daniel-mar | 66 | if (!hLib) return 0; |
67 | fGetTickCount64 = (f_GetTickCount64)(void*)GetProcAddress(hLib, "GetTickCount64"); |
||
68 | if (fGetTickCount64 != 0) { |
||
69 | res = fGetTickCount64(); |
||
70 | FreeLibrary(hLib); |
||
71 | } else { |
||
72 | #pragma warning(suppress : 28159) |
||
73 | res = (ULONGLONG)GetTickCount(); |
||
74 | } |
||
75 | |||
76 | return res; |
||
77 | } |
||
78 | |||
402 | daniel-mar | 79 | // --------------------------------- |
80 | |||
444 | daniel-mar | 81 | HANDLE _BeginUpdateResource( |
82 | LPCTSTR pFileName, |
||
83 | BOOL bDeleteExistingResources |
||
259 | daniel-mar | 84 | ) { |
444 | daniel-mar | 85 | #ifdef UNICODE |
86 | return BeginUpdateResource(pFileName, bDeleteExistingResources); |
||
87 | #else |
||
411 | daniel-mar | 88 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 89 | return BeginUpdateResourceA(pFileName, bDeleteExistingResources); |
90 | } else { |
||
91 | return WineBeginUpdateResourceA(pFileName, bDeleteExistingResources); |
||
92 | } |
||
444 | daniel-mar | 93 | #endif |
259 | daniel-mar | 94 | } |
95 | |||
96 | // --------------------------------- |
||
97 | |||
444 | daniel-mar | 98 | BOOL _EndUpdateResource( |
268 | daniel-mar | 99 | HANDLE hUpdate, |
100 | BOOL fDiscard |
||
259 | daniel-mar | 101 | ) { |
444 | daniel-mar | 102 | #ifdef UNICODE |
103 | return EndUpdateResource(hUpdate, fDiscard); |
||
104 | #else |
||
411 | daniel-mar | 105 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 106 | return EndUpdateResourceA(hUpdate, fDiscard); |
107 | } else { |
||
108 | return WineEndUpdateResourceA(hUpdate, fDiscard); |
||
109 | } |
||
444 | daniel-mar | 110 | #endif |
259 | daniel-mar | 111 | } |
112 | |||
113 | // --------------------------------- |
||
114 | |||
444 | daniel-mar | 115 | BOOL _UpdateResource( |
116 | HANDLE hUpdate, |
||
117 | LPCTSTR lpType, |
||
118 | LPCTSTR lpName, |
||
119 | WORD wLanguage, |
||
120 | LPVOID lpData, |
||
121 | DWORD cb |
||
259 | daniel-mar | 122 | ) { |
444 | daniel-mar | 123 | #ifdef UNICODE |
124 | return UpdateResource(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
125 | #else |
||
411 | daniel-mar | 126 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 127 | return UpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
128 | } else { |
||
129 | return WineUpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
130 | } |
||
444 | daniel-mar | 131 | #endif |
259 | daniel-mar | 132 | } |
274 | daniel-mar | 133 | |
134 | typedef void(__stdcall* f_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo); |
||
135 | void _GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
||
136 | HMODULE hLib; |
||
137 | f_GetNativeSystemInfo fGetNativeSystemInfo; |
||
138 | |||
444 | daniel-mar | 139 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
274 | daniel-mar | 140 | if (!hLib) return; |
141 | fGetNativeSystemInfo = (f_GetNativeSystemInfo)(void*)GetProcAddress(hLib, "GetNativeSystemInfo"); |
||
142 | if (fGetNativeSystemInfo != 0) { |
||
143 | fGetNativeSystemInfo(lpSystemInfo); |
||
144 | FreeLibrary(hLib); |
||
145 | } |
||
146 | else { |
||
147 | GetSystemInfo(lpSystemInfo); |
||
148 | } |
||
149 | } |
||
357 | daniel-mar | 150 | |
151 | typedef BOOL(__stdcall* f_ImageRemoveCertificate)(HANDLE FileHandle, DWORD Index); |
||
152 | BOOL _ImageRemoveCertificate(HANDLE FileHandle, DWORD Index) { |
||
153 | HMODULE hLib; |
||
154 | f_ImageRemoveCertificate fImageRemoveCertificate; |
||
155 | BOOL res = FALSE; |
||
156 | |||
462 | daniel-mar | 157 | #ifndef _WIN64 |
158 | // Win32s (Windows 3.11) compatibility: LoadLibrary() will output a visual message if IMAGEHLP.DLL is not existing! |
||
463 | daniel-mar | 159 | char* sys_path; |
160 | sys_path = (char*)malloc(MAX_PATH); |
||
462 | daniel-mar | 161 | if (GetSystemDirectoryA(sys_path, MAX_PATH)) { |
463 | daniel-mar | 162 | char* dllfile; |
163 | dllfile = (char*)malloc(MAX_PATH); |
||
164 | if (dllfile) { |
||
165 | sprintf(dllfile, "%s\\IMAGEHLP.DLL", sys_path); |
||
166 | if (GetFileAttributesA(dllfile) == INVALID_FILE_ATTRIBUTES) { |
||
167 | // File does not exist |
||
168 | free(dllfile); |
||
169 | return true; |
||
170 | } |
||
171 | else { |
||
172 | free(dllfile); |
||
173 | } |
||
462 | daniel-mar | 174 | } |
175 | } |
||
463 | daniel-mar | 176 | free(sys_path); |
462 | daniel-mar | 177 | #endif |
178 | |||
444 | daniel-mar | 179 | hLib = LoadLibrary(TEXT("IMAGEHLP.DLL")); |
357 | daniel-mar | 180 | if (!hLib) return FALSE; |
181 | fImageRemoveCertificate = (f_ImageRemoveCertificate)(void*)GetProcAddress(hLib, "ImageRemoveCertificate"); |
||
182 | if (fImageRemoveCertificate != 0) { |
||
183 | res = fImageRemoveCertificate(FileHandle, Index); |
||
184 | FreeLibrary(hLib); |
||
185 | } |
||
186 | |||
187 | return res; |
||
188 | } |
||
479 | daniel-mar | 189 | |
480 | daniel-mar | 190 | Ptr NewPtr(size_t size) { |
479 | daniel-mar | 191 | HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, size); |
192 | if (!hMem) |
||
193 | return NULL; |
||
480 | daniel-mar | 194 | return (Ptr)GlobalLock(hMem); |
479 | daniel-mar | 195 | } |
196 | |||
480 | daniel-mar | 197 | Ptr NewPtrClear(size_t size) { |
479 | daniel-mar | 198 | HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size); |
199 | if (!hMem) |
||
200 | return NULL; |
||
480 | daniel-mar | 201 | return (Ptr)GlobalLock(hMem); |
479 | daniel-mar | 202 | } |
203 | |||
480 | daniel-mar | 204 | void DisposePtr(Ptr ptr) { |
479 | daniel-mar | 205 | HGLOBAL hMem = GlobalHandle((LPCVOID)ptr); |
206 | if (!hMem) |
||
207 | return; |
||
208 | if (GlobalUnlock(hMem)) GlobalFree(hMem); |
||
536 | daniel-mar | 209 | } |