Login | ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/filter_foundry/trunk/telegraphics_common/tt/compat_win.c
Revision: 357
Committed: Sat Oct 16 18:45:48 2021 UTC (8 months, 2 weeks ago) by daniel-marschall
Content type: text/x-csrc
File size: 4634 byte(s)
Log Message:
In case filter is digitally signed, the signature will be removed for standalone filters

File Contents

# User Rev Content
1 daniel-marschall 259 /*
2 daniel-marschall 268 This file is part of a common library
3 daniel-marschall 259 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){
25 daniel-marschall 311 #ifdef _WIN64
26     // 64 bit OS is never Win9x, so it must be WinNT
27     return true;
28     #else
29 daniel-marschall 259 OSVERSIONINFO osv;
30     osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
31     #pragma warning(suppress : 4996 28159)
32     return GetVersionEx(&osv) && osv.dwPlatformId == VER_PLATFORM_WIN32_NT;
33 daniel-marschall 311 #endif
34 daniel-marschall 259 }
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)(
59 daniel-marschall 268 LPCSTR pFileName,
60     BOOL bDeleteExistingResources
61 daniel-marschall 259 );
62     HANDLE _BeginUpdateResource/*A*/(
63 daniel-marschall 268 LPCSTR pFileName,
64     BOOL bDeleteExistingResources
65 daniel-marschall 259 ) {
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)(
82 daniel-marschall 268 HANDLE hUpdate,
83     BOOL fDiscard
84 daniel-marschall 259 );
85    
86     BOOL _EndUpdateResource/*A*/(
87 daniel-marschall 268 HANDLE hUpdate,
88     BOOL fDiscard
89 daniel-marschall 259 ) {
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)(
106 daniel-marschall 268 HANDLE hUpdate,
107     LPCSTR lpType,
108     LPCSTR lpName,
109     WORD wLanguage,
110     LPVOID lpData,
111     DWORD cb
112 daniel-marschall 259 );
113     BOOL _UpdateResource/*A*/(
114 daniel-marschall 268 HANDLE hUpdate,
115     LPCSTR lpType,
116     LPCSTR lpName,
117     WORD wLanguage,
118     LPVOID lpData,
119     DWORD cb
120 daniel-marschall 259 ) {
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     }
133 daniel-marschall 274
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     }
150 daniel-marschall 357
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    
157     hLib = LoadLibraryA("IMAGEHLP.DLL");
158     if (!hLib) return FALSE;
159     fImageRemoveCertificate = (f_ImageRemoveCertificate)(void*)GetProcAddress(hLib, "ImageRemoveCertificate");
160     if (fImageRemoveCertificate != 0) {
161     res = fImageRemoveCertificate(FileHandle, Index);
162     FreeLibrary(hLib);
163     }
164    
165     return res;
166     }