Rev 414 | Rev 444 | 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 | |||
35 | hLib = LoadLibraryA("KERNEL32.DLL"); |
||
36 | if (!hLib) return 0; |
||
37 | fGetVersionEx = (f_GetVersionEx)(void*)GetProcAddress(hLib, "GetVersionExA"); |
||
38 | if (fGetVersionEx != 0) { |
||
39 | OSVERSIONINFO osv; |
||
40 | osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
||
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 | |||
64 | hLib = LoadLibraryA("KERNEL32.DLL"); |
||
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 | |||
259 | daniel-mar | 80 | HANDLE _BeginUpdateResource/*A*/( |
268 | daniel-mar | 81 | LPCSTR pFileName, |
82 | BOOL bDeleteExistingResources |
||
259 | daniel-mar | 83 | ) { |
411 | daniel-mar | 84 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 85 | return BeginUpdateResourceA(pFileName, bDeleteExistingResources); |
86 | } else { |
||
87 | return WineBeginUpdateResourceA(pFileName, bDeleteExistingResources); |
||
88 | } |
||
259 | daniel-mar | 89 | } |
90 | |||
91 | // --------------------------------- |
||
92 | |||
93 | BOOL _EndUpdateResource/*A*/( |
||
268 | daniel-mar | 94 | HANDLE hUpdate, |
95 | BOOL fDiscard |
||
259 | daniel-mar | 96 | ) { |
411 | daniel-mar | 97 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 98 | return EndUpdateResourceA(hUpdate, fDiscard); |
99 | } else { |
||
100 | return WineEndUpdateResourceA(hUpdate, fDiscard); |
||
101 | } |
||
259 | daniel-mar | 102 | } |
103 | |||
104 | // --------------------------------- |
||
105 | |||
106 | BOOL _UpdateResource/*A*/( |
||
268 | daniel-mar | 107 | HANDLE hUpdate, |
108 | LPCSTR lpType, |
||
109 | LPCSTR lpName, |
||
110 | WORD wLanguage, |
||
111 | LPVOID lpData, |
||
112 | DWORD cb |
||
259 | daniel-mar | 113 | ) { |
411 | daniel-mar | 114 | if (Implements3264ResourceAPI()) { |
402 | daniel-mar | 115 | return UpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
116 | } else { |
||
117 | return WineUpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
118 | } |
||
259 | daniel-mar | 119 | } |
274 | daniel-mar | 120 | |
121 | typedef void(__stdcall* f_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo); |
||
122 | void _GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
||
123 | HMODULE hLib; |
||
124 | f_GetNativeSystemInfo fGetNativeSystemInfo; |
||
125 | |||
126 | hLib = LoadLibraryA("KERNEL32.DLL"); |
||
127 | if (!hLib) return; |
||
128 | fGetNativeSystemInfo = (f_GetNativeSystemInfo)(void*)GetProcAddress(hLib, "GetNativeSystemInfo"); |
||
129 | if (fGetNativeSystemInfo != 0) { |
||
130 | fGetNativeSystemInfo(lpSystemInfo); |
||
131 | FreeLibrary(hLib); |
||
132 | } |
||
133 | else { |
||
134 | GetSystemInfo(lpSystemInfo); |
||
135 | } |
||
136 | } |
||
357 | daniel-mar | 137 | |
138 | typedef BOOL(__stdcall* f_ImageRemoveCertificate)(HANDLE FileHandle, DWORD Index); |
||
139 | BOOL _ImageRemoveCertificate(HANDLE FileHandle, DWORD Index) { |
||
140 | HMODULE hLib; |
||
141 | f_ImageRemoveCertificate fImageRemoveCertificate; |
||
142 | BOOL res = FALSE; |
||
143 | |||
144 | hLib = LoadLibraryA("IMAGEHLP.DLL"); |
||
145 | if (!hLib) return FALSE; |
||
146 | fImageRemoveCertificate = (f_ImageRemoveCertificate)(void*)GetProcAddress(hLib, "ImageRemoveCertificate"); |
||
147 | if (fImageRemoveCertificate != 0) { |
||
148 | res = fImageRemoveCertificate(FileHandle, Index); |
||
149 | FreeLibrary(hLib); |
||
150 | } |
||
151 | |||
152 | return res; |
||
153 | } |