Rev 419 | Rev 462 | Go to most recent revision | 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 |
259 | daniel-mar | 3 | Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au |
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> |
||
21 | |||
22 | #include "compat_win.h" |
||
402 | daniel-mar | 23 | #include "compat_win_resource.h" |
259 | daniel-mar | 24 | |
411 | daniel-mar | 25 | typedef BOOL(__stdcall* f_GetVersionEx)(LPOSVERSIONINFOA lpVersionInformation); |
26 | Boolean Implements3264ResourceAPI() { |
||
311 | daniel-mar | 27 | #ifdef _WIN64 |
28 | // 64 bit OS is never Win9x, so it must be WinNT |
||
29 | return true; |
||
30 | #else |
||
411 | daniel-mar | 31 | HMODULE hLib; |
32 | f_GetVersionEx fGetVersionEx; |
||
33 | BOOL res; |
||
34 | |||
444 | daniel-mar | 35 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
411 | daniel-mar | 36 | if (!hLib) return 0; |
37 | fGetVersionEx = (f_GetVersionEx)(void*)GetProcAddress(hLib, "GetVersionExA"); |
||
38 | if (fGetVersionEx != 0) { |
||
444 | daniel-mar | 39 | OSVERSIONINFOA osv; |
40 | osv.dwOSVersionInfoSize = sizeof(osv); |
||
411 | daniel-mar | 41 | res = fGetVersionEx(&osv); |
42 | FreeLibrary(hLib); |
||
414 | daniel-mar | 43 | // Windows NT 3.51 does implement GetVersionExA() and UpdateResourceA(), but it doesn't know about 64 bit images. |
411 | daniel-mar | 44 | // Windows NT 4.0 does implement UpdateResourceA(), and it can handle 64 bit images |
45 | return res && osv.dwMajorVersion >= 4 && osv.dwPlatformId == VER_PLATFORM_WIN32_NT; |
||
46 | } |
||
47 | else { |
||
414 | daniel-mar | 48 | // Windows NT 3.1 doesn't have GetVersionExA(), doesn't implement UpdateResourceA(), and doesn't know about 64 bit images |
49 | // Therefore, we conclude that if GetVersionExA() is missing, then we are on a system that requires manual resource processing |
||
411 | daniel-mar | 50 | FreeLibrary(hLib); |
51 | return false; |
||
52 | } |
||
311 | daniel-mar | 53 | #endif |
259 | daniel-mar | 54 | } |
55 | |||
56 | // --------------------------------- |
||
57 | |||
58 | typedef ULONGLONG(__stdcall* f_GetTickCount64)(); |
||
59 | ULONGLONG _GetTickCount64() { |
||
60 | HMODULE hLib; |
||
61 | f_GetTickCount64 fGetTickCount64; |
||
62 | ULONGLONG res; |
||
63 | |||
444 | daniel-mar | 64 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
259 | daniel-mar | 65 | if (!hLib) return 0; |
66 | fGetTickCount64 = (f_GetTickCount64)(void*)GetProcAddress(hLib, "GetTickCount64"); |
||
67 | if (fGetTickCount64 != 0) { |
||
68 | res = fGetTickCount64(); |
||
69 | FreeLibrary(hLib); |
||
70 | } else { |
||
71 | #pragma warning(suppress : 28159) |
||
72 | res = (ULONGLONG)GetTickCount(); |
||
73 | } |
||
74 | |||
75 | return res; |
||
76 | } |
||
77 | |||
402 | daniel-mar | 78 | // --------------------------------- |
79 | |||
444 | daniel-mar | 80 | HANDLE _BeginUpdateResource( |
81 | LPCTSTR pFileName, |
||
82 | BOOL bDeleteExistingResources |
||
259 | daniel-mar | 83 | ) { |
444 | daniel-mar | 84 | #ifdef UNICODE |
85 | return BeginUpdateResource(pFileName, bDeleteExistingResources); |
||
86 | #else |
||
411 | daniel-mar | 87 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 88 | return BeginUpdateResourceA(pFileName, bDeleteExistingResources); |
89 | } else { |
||
90 | return WineBeginUpdateResourceA(pFileName, bDeleteExistingResources); |
||
91 | } |
||
444 | daniel-mar | 92 | #endif |
259 | daniel-mar | 93 | } |
94 | |||
95 | // --------------------------------- |
||
96 | |||
444 | daniel-mar | 97 | BOOL _EndUpdateResource( |
268 | daniel-mar | 98 | HANDLE hUpdate, |
99 | BOOL fDiscard |
||
259 | daniel-mar | 100 | ) { |
444 | daniel-mar | 101 | #ifdef UNICODE |
102 | return EndUpdateResource(hUpdate, fDiscard); |
||
103 | #else |
||
411 | daniel-mar | 104 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 105 | return EndUpdateResourceA(hUpdate, fDiscard); |
106 | } else { |
||
107 | return WineEndUpdateResourceA(hUpdate, fDiscard); |
||
108 | } |
||
444 | daniel-mar | 109 | #endif |
259 | daniel-mar | 110 | } |
111 | |||
112 | // --------------------------------- |
||
113 | |||
444 | daniel-mar | 114 | BOOL _UpdateResource( |
115 | HANDLE hUpdate, |
||
116 | LPCTSTR lpType, |
||
117 | LPCTSTR lpName, |
||
118 | WORD wLanguage, |
||
119 | LPVOID lpData, |
||
120 | DWORD cb |
||
259 | daniel-mar | 121 | ) { |
444 | daniel-mar | 122 | #ifdef UNICODE |
123 | return UpdateResource(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
124 | #else |
||
411 | daniel-mar | 125 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 126 | return UpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
127 | } else { |
||
128 | return WineUpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
129 | } |
||
444 | daniel-mar | 130 | #endif |
259 | daniel-mar | 131 | } |
274 | daniel-mar | 132 | |
133 | typedef void(__stdcall* f_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo); |
||
134 | void _GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
||
135 | HMODULE hLib; |
||
136 | f_GetNativeSystemInfo fGetNativeSystemInfo; |
||
137 | |||
444 | daniel-mar | 138 | hLib = LoadLibrary(TEXT("KERNEL32.DLL")); |
274 | daniel-mar | 139 | if (!hLib) return; |
140 | fGetNativeSystemInfo = (f_GetNativeSystemInfo)(void*)GetProcAddress(hLib, "GetNativeSystemInfo"); |
||
141 | if (fGetNativeSystemInfo != 0) { |
||
142 | fGetNativeSystemInfo(lpSystemInfo); |
||
143 | FreeLibrary(hLib); |
||
144 | } |
||
145 | else { |
||
146 | GetSystemInfo(lpSystemInfo); |
||
147 | } |
||
148 | } |
||
357 | daniel-mar | 149 | |
150 | typedef BOOL(__stdcall* f_ImageRemoveCertificate)(HANDLE FileHandle, DWORD Index); |
||
151 | BOOL _ImageRemoveCertificate(HANDLE FileHandle, DWORD Index) { |
||
152 | HMODULE hLib; |
||
153 | f_ImageRemoveCertificate fImageRemoveCertificate; |
||
154 | BOOL res = FALSE; |
||
155 | |||
444 | daniel-mar | 156 | hLib = LoadLibrary(TEXT("IMAGEHLP.DLL")); |
357 | daniel-mar | 157 | if (!hLib) return FALSE; |
158 | fImageRemoveCertificate = (f_ImageRemoveCertificate)(void*)GetProcAddress(hLib, "ImageRemoveCertificate"); |
||
159 | if (fImageRemoveCertificate != 0) { |
||
160 | res = fImageRemoveCertificate(FileHandle, Index); |
||
161 | FreeLibrary(hLib); |
||
162 | } |
||
163 | |||
164 | return res; |
||
165 | } |