1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-08-14 21:42:50 +02:00

Check the minimum Windows version before trying to load the CEF binaries

Fix for issue #452
This commit is contained in:
salvadordf
2023-04-15 14:59:17 +02:00
parent ec6dfa64e2
commit a0e2bcfbd8
4 changed files with 70 additions and 3 deletions

View File

@@ -367,6 +367,7 @@ type
function CheckCEFResources : boolean; virtual; function CheckCEFResources : boolean; virtual;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
function CheckCEFDLL : boolean; virtual; function CheckCEFDLL : boolean; virtual;
function CheckWindowsVersion: boolean; virtual;
{$ENDIF} {$ENDIF}
procedure ShowErrorMessageDlg(const aError : string); virtual; procedure ShowErrorMessageDlg(const aError : string); virtual;
function ParseProcessType : TCefProcessType; function ParseProcessType : TCefProcessType;
@@ -1205,6 +1206,23 @@ begin
ShowErrorMessageDlg(FLastErrorMessage); ShowErrorMessageDlg(FLastErrorMessage);
end; end;
end; end;
function TCefApplicationCore.CheckWindowsVersion : boolean;
begin
// Chromium 109 requires Windows 10 or later.
// https://github.com/salvadordf/CEF4Delphi/issues/452
if CheckRealWindowsVersion(10, 0) then
Result := True
else
begin
Result := False;
FStatus := asErrorWindowsVersion;
FLastErrorMessage := 'Unsupported Windows version !' +
CRLF + CRLF +
'Chromium requires Windows 10 or later.';
ShowErrorMessageDlg(FLastErrorMessage);
end;
end;
{$ENDIF} {$ENDIF}
function TCefApplicationCore.CheckCEFLibrary : boolean; function TCefApplicationCore.CheckCEFLibrary : boolean;
@@ -1223,8 +1241,10 @@ begin
chdir(GetModulePath); chdir(GetModulePath);
end; end;
Result := CheckCEFResources Result := CheckCEFResources;
{$IFDEF MSWINDOWS}and CheckCEFDLL{$ENDIF}; {$IFDEF MSWINDOWS}
Result := Result and CheckWindowsVersion and CheckCEFDLL;
{$ENDIF}
if FSetCurrentDir then chdir(TempOldDir); if FSetCurrentDir then chdir(TempOldDir);
end; end;

View File

@@ -83,6 +83,7 @@ const
SHLWAPIDLL = 'shlwapi.dll'; SHLWAPIDLL = 'shlwapi.dll';
NTDLL = 'ntdll.dll'; NTDLL = 'ntdll.dll';
User32DLL = 'User32.dll'; User32DLL = 'User32.dll';
Netapi32DLL = 'Netapi32.dll';
function CefColorGetA(color: TCefColor): Byte; function CefColorGetA(color: TCefColor): Byte;
function CefColorGetR(color: TCefColor): byte; function CefColorGetR(color: TCefColor): byte;
@@ -182,6 +183,8 @@ function PathIsURLAnsi(pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name
function PathIsURLUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsURLW'; function PathIsURLUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsURLW';
function ShutdownBlockReasonCreate(hWnd: HWND; Reason: LPCWSTR): Bool; stdcall; external User32DLL; function ShutdownBlockReasonCreate(hWnd: HWND; Reason: LPCWSTR): Bool; stdcall; external User32DLL;
function ShutdownBlockReasonDestroy(hWnd: HWND): Bool; stdcall; external User32DLL; function ShutdownBlockReasonDestroy(hWnd: HWND): Bool; stdcall; external User32DLL;
function NetServerGetInfo(servername: LPWSTR; level: DWORD; out bufptr: Pointer): DWORD; stdcall; external Netapi32DLL;
function NetApiBufferFree(Buffer: Pointer): DWORD; stdcall; external Netapi32DLL;
{$IFNDEF DELPHI12_UP} {$IFNDEF DELPHI12_UP}
const const
@@ -227,6 +230,8 @@ procedure UInt64ToFileVersionInfo(const aVersion : uint64; var aVersionInfo : TF
function GetExtendedFileVersion(const aFileName : ustring) : uint64; function GetExtendedFileVersion(const aFileName : ustring) : uint64;
function GetDLLVersion(const aDLLFile : ustring; var aVersionInfo : TFileVersionInfo) : boolean; function GetDLLVersion(const aDLLFile : ustring; var aVersionInfo : TFileVersionInfo) : boolean;
procedure OutputLastErrorMessage; procedure OutputLastErrorMessage;
function GetRealWindowsVersion(var aMajor, aMinor: cardinal) : boolean;
function CheckRealWindowsVersion(aMajor, aMinor: cardinal) : boolean;
{$ENDIF} {$ENDIF}
function SplitLongString(aSrcString : string) : string; function SplitLongString(aSrcString : string) : string;
@@ -1515,6 +1520,47 @@ begin
{$ENDIF} {$ENDIF}
end; end;
function GetRealWindowsVersion(var aMajor, aMinor: cardinal) : boolean;
type
SERVER_INFO_101 = record
sv101_platform_id : DWORD;
sv101_name : LPWSTR;
sv101_version_major : DWORD;
sv101_version_minor : DWORD;
sv101_type : DWORD;
sv101_comment : LPWSTR;
end;
PSERVER_INFO_101 = ^SERVER_INFO_101;
const
MAJOR_VERSION_MASK = $0F;
NO_ERROR = 0;
var
TempBuffer : PSERVER_INFO_101;
begin
Result := False;
TempBuffer := nil;
if (NetServerGetInfo(nil, 101, Pointer(TempBuffer)) = NO_ERROR) then
try
aMajor := TempBuffer.sv101_version_major and MAJOR_VERSION_MASK;
aMinor := TempBuffer.sv101_version_minor;
Result := True;
finally
NetApiBufferFree(TempBuffer);
end;
end;
function CheckRealWindowsVersion(aMajor, aMinor: cardinal) : boolean;
var
TempMajor, TempMinor: cardinal;
begin
Result := GetRealWindowsVersion(TempMajor, TempMinor) and
((TempMajor > aMajor) or
((TempMajor = aMajor) and (TempMinor >= aMinor)));
end;
function GetDLLVersion(const aDLLFile : ustring; var aVersionInfo : TFileVersionInfo) : boolean; function GetDLLVersion(const aDLLFile : ustring; var aVersionInfo : TFileVersionInfo) : boolean;
var var
TempVersion : uint64; TempVersion : uint64;

View File

@@ -475,6 +475,7 @@ type
asUnloaded, asUnloaded,
asErrorMissingFiles, asErrorMissingFiles,
asErrorDLLVersion, asErrorDLLVersion,
asErrorWindowsVersion,
asErrorLoadingLibrary, asErrorLoadingLibrary,
asErrorInitializingLibrary, asErrorInitializingLibrary,
asErrorExecutingProcess); asErrorExecutingProcess);

View File

@@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 479, "InternalVersion" : 480,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "112.2.9" "Version" : "112.2.9"
} }