Rev 274 | Rev 357 | 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" |
||
23 | |||
24 | Boolean isWin32NT(void){ |
||
311 | daniel-mar | 25 | #ifdef _WIN64 |
26 | // 64 bit OS is never Win9x, so it must be WinNT |
||
27 | return true; |
||
28 | #else |
||
259 | daniel-mar | 29 | OSVERSIONINFO osv; |
30 | osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
||
31 | #pragma warning(suppress : 4996 28159) |
||
32 | return GetVersionEx(&osv) && osv.dwPlatformId == VER_PLATFORM_WIN32_NT; |
||
311 | daniel-mar | 33 | #endif |
259 | daniel-mar | 34 | } |
35 | |||
36 | // --------------------------------- |
||
37 | |||
38 | typedef ULONGLONG(__stdcall* f_GetTickCount64)(); |
||
39 | ULONGLONG _GetTickCount64() { |
||
40 | HMODULE hLib; |
||
41 | f_GetTickCount64 fGetTickCount64; |
||
42 | ULONGLONG res; |
||
43 | |||
44 | hLib = LoadLibraryA("KERNEL32.DLL"); |
||
45 | if (!hLib) return 0; |
||
46 | fGetTickCount64 = (f_GetTickCount64)(void*)GetProcAddress(hLib, "GetTickCount64"); |
||
47 | if (fGetTickCount64 != 0) { |
||
48 | res = fGetTickCount64(); |
||
49 | FreeLibrary(hLib); |
||
50 | } else { |
||
51 | #pragma warning(suppress : 28159) |
||
52 | res = (ULONGLONG)GetTickCount(); |
||
53 | } |
||
54 | |||
55 | return res; |
||
56 | } |
||
57 | |||
58 | typedef HANDLE(__stdcall *f_BeginUpdateResourceA)( |
||
268 | daniel-mar | 59 | LPCSTR pFileName, |
60 | BOOL bDeleteExistingResources |
||
259 | daniel-mar | 61 | ); |
62 | HANDLE _BeginUpdateResource/*A*/( |
||
268 | daniel-mar | 63 | LPCSTR pFileName, |
64 | BOOL bDeleteExistingResources |
||
259 | daniel-mar | 65 | ) { |
66 | HMODULE hLib; |
||
67 | f_BeginUpdateResourceA fBeginUpdateResourceA; |
||
68 | HANDLE res; |
||
69 | |||
70 | hLib = LoadLibraryA(isWin32NT() ? "KERNEL32.DLL" : "UNICOWS.DLL"); |
||
71 | if (!hLib) return 0; |
||
72 | fBeginUpdateResourceA = (f_BeginUpdateResourceA)(void*)GetProcAddress(hLib, "BeginUpdateResourceA"); |
||
73 | res = fBeginUpdateResourceA(pFileName, bDeleteExistingResources); |
||
74 | FreeLibrary(hLib); |
||
75 | |||
76 | return res; |
||
77 | } |
||
78 | |||
79 | // --------------------------------- |
||
80 | |||
81 | typedef BOOL(__stdcall *f_EndUpdateResourceA)( |
||
268 | daniel-mar | 82 | HANDLE hUpdate, |
83 | BOOL fDiscard |
||
259 | daniel-mar | 84 | ); |
85 | |||
86 | BOOL _EndUpdateResource/*A*/( |
||
268 | daniel-mar | 87 | HANDLE hUpdate, |
88 | BOOL fDiscard |
||
259 | daniel-mar | 89 | ) { |
90 | HMODULE hLib; |
||
91 | f_EndUpdateResourceA fEndUpdateResourceA; |
||
92 | BOOL res; |
||
93 | |||
94 | hLib = LoadLibraryA(isWin32NT() ? "KERNEL32.DLL" : "UNICOWS.DLL"); |
||
95 | if (!hLib) return 0; |
||
96 | fEndUpdateResourceA = (f_EndUpdateResourceA)(void*)GetProcAddress(hLib, "EndUpdateResourceA"); |
||
97 | res = fEndUpdateResourceA(hUpdate, fDiscard); |
||
98 | FreeLibrary(hLib); |
||
99 | |||
100 | return res; |
||
101 | } |
||
102 | |||
103 | // --------------------------------- |
||
104 | |||
105 | typedef BOOL(__stdcall *f_UpdateResourceA)( |
||
268 | daniel-mar | 106 | HANDLE hUpdate, |
107 | LPCSTR lpType, |
||
108 | LPCSTR lpName, |
||
109 | WORD wLanguage, |
||
110 | LPVOID lpData, |
||
111 | DWORD cb |
||
259 | daniel-mar | 112 | ); |
113 | BOOL _UpdateResource/*A*/( |
||
268 | daniel-mar | 114 | HANDLE hUpdate, |
115 | LPCSTR lpType, |
||
116 | LPCSTR lpName, |
||
117 | WORD wLanguage, |
||
118 | LPVOID lpData, |
||
119 | DWORD cb |
||
259 | daniel-mar | 120 | ) { |
121 | HMODULE hLib; |
||
122 | f_UpdateResourceA fUpdateResourceA; |
||
123 | BOOL res; |
||
124 | |||
125 | hLib = LoadLibraryA(isWin32NT() ? "KERNEL32.DLL" : "UNICOWS.DLL"); |
||
126 | if (!hLib) return 0; |
||
127 | fUpdateResourceA = (f_UpdateResourceA)(void*)GetProcAddress(hLib, "UpdateResourceA"); |
||
128 | res = fUpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb); |
||
129 | FreeLibrary(hLib); |
||
130 | |||
131 | return res; |
||
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 | |||
139 | hLib = LoadLibraryA("KERNEL32.DLL"); |
||
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 | } |