Subversion Repositories filter_foundry

Rev

Rev 419 | Rev 462 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of a common library
  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. #include "compat_win_resource.h"
  24.  
  25. typedef BOOL(__stdcall* f_GetVersionEx)(LPOSVERSIONINFOA lpVersionInformation);
  26. Boolean Implements3264ResourceAPI() {
  27. #ifdef _WIN64
  28.         // 64 bit OS is never Win9x, so it must be WinNT
  29.         return true;
  30. #else
  31.         HMODULE hLib;
  32.         f_GetVersionEx fGetVersionEx;
  33.         BOOL res;
  34.  
  35.         hLib = LoadLibrary(TEXT("KERNEL32.DLL"));
  36.         if (!hLib) return 0;
  37.         fGetVersionEx = (f_GetVersionEx)(void*)GetProcAddress(hLib, "GetVersionExA");
  38.         if (fGetVersionEx != 0) {
  39.                 OSVERSIONINFOA osv;
  40.                 osv.dwOSVersionInfoSize = sizeof(osv);
  41.                 res = fGetVersionEx(&osv);
  42.                 FreeLibrary(hLib);
  43.                 // Windows NT 3.51 does implement GetVersionExA() and UpdateResourceA(), but it doesn't know about 64 bit images.
  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 {
  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
  50.                 FreeLibrary(hLib);
  51.                 return false;
  52.         }
  53. #endif
  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 = LoadLibrary(TEXT("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.  
  78. // ---------------------------------
  79.  
  80. HANDLE _BeginUpdateResource(
  81.         LPCTSTR pFileName,
  82.         BOOL    bDeleteExistingResources
  83. ) {
  84.         #ifdef UNICODE
  85.         return BeginUpdateResource(pFileName, bDeleteExistingResources);
  86.         #else
  87.         if (Implements3264ResourceAPI()) {
  88.                 return BeginUpdateResourceA(pFileName, bDeleteExistingResources);
  89.         } else {
  90.                 return WineBeginUpdateResourceA(pFileName, bDeleteExistingResources);
  91.         }
  92.         #endif
  93. }
  94.  
  95. // ---------------------------------
  96.  
  97. BOOL _EndUpdateResource(
  98.         HANDLE hUpdate,
  99.         BOOL   fDiscard
  100. ) {
  101.         #ifdef UNICODE
  102.         return EndUpdateResource(hUpdate, fDiscard);
  103.         #else
  104.         if (Implements3264ResourceAPI()) {
  105.                 return EndUpdateResourceA(hUpdate, fDiscard);
  106.         } else {
  107.                 return WineEndUpdateResourceA(hUpdate, fDiscard);
  108.         }
  109.         #endif
  110. }
  111.  
  112. // ---------------------------------
  113.  
  114. BOOL _UpdateResource(
  115.         HANDLE  hUpdate,
  116.         LPCTSTR lpType,
  117.         LPCTSTR lpName,
  118.         WORD    wLanguage,
  119.         LPVOID  lpData,
  120.         DWORD   cb
  121. ) {
  122.         #ifdef UNICODE
  123.         return UpdateResource(hUpdate, lpType, lpName, wLanguage, lpData, cb);
  124.         #else
  125.         if (Implements3264ResourceAPI()) {
  126.                 return UpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb);
  127.         } else {
  128.                 return WineUpdateResourceA(hUpdate, lpType, lpName, wLanguage, lpData, cb);
  129.         }
  130.         #endif
  131. }
  132.  
  133. typedef void(__stdcall* f_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
  134. void _GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) {
  135.         HMODULE hLib;
  136.         f_GetNativeSystemInfo fGetNativeSystemInfo;
  137.  
  138.         hLib = LoadLibrary(TEXT("KERNEL32.DLL"));
  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. }
  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.  
  156.         hLib = LoadLibrary(TEXT("IMAGEHLP.DLL"));
  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. }
  166.