diff --git a/source/uCEFApplicationCore.pas b/source/uCEFApplicationCore.pas index b40abb6e..733b3cdd 100644 --- a/source/uCEFApplicationCore.pas +++ b/source/uCEFApplicationCore.pas @@ -367,6 +367,7 @@ type function CheckCEFResources : boolean; virtual; {$IFDEF MSWINDOWS} function CheckCEFDLL : boolean; virtual; + function CheckWindowsVersion: boolean; virtual; {$ENDIF} procedure ShowErrorMessageDlg(const aError : string); virtual; function ParseProcessType : TCefProcessType; @@ -1205,6 +1206,23 @@ begin ShowErrorMessageDlg(FLastErrorMessage); 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} function TCefApplicationCore.CheckCEFLibrary : boolean; @@ -1223,8 +1241,10 @@ begin chdir(GetModulePath); end; - Result := CheckCEFResources - {$IFDEF MSWINDOWS}and CheckCEFDLL{$ENDIF}; + Result := CheckCEFResources; + {$IFDEF MSWINDOWS} + Result := Result and CheckWindowsVersion and CheckCEFDLL; + {$ENDIF} if FSetCurrentDir then chdir(TempOldDir); end; diff --git a/source/uCEFMiscFunctions.pas b/source/uCEFMiscFunctions.pas index b05db682..bf471993 100644 --- a/source/uCEFMiscFunctions.pas +++ b/source/uCEFMiscFunctions.pas @@ -83,6 +83,7 @@ const SHLWAPIDLL = 'shlwapi.dll'; NTDLL = 'ntdll.dll'; User32DLL = 'User32.dll'; + Netapi32DLL = 'Netapi32.dll'; function CefColorGetA(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 ShutdownBlockReasonCreate(hWnd: HWND; Reason: LPCWSTR): 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} const @@ -227,6 +230,8 @@ procedure UInt64ToFileVersionInfo(const aVersion : uint64; var aVersionInfo : TF function GetExtendedFileVersion(const aFileName : ustring) : uint64; function GetDLLVersion(const aDLLFile : ustring; var aVersionInfo : TFileVersionInfo) : boolean; procedure OutputLastErrorMessage; +function GetRealWindowsVersion(var aMajor, aMinor: cardinal) : boolean; +function CheckRealWindowsVersion(aMajor, aMinor: cardinal) : boolean; {$ENDIF} function SplitLongString(aSrcString : string) : string; @@ -1515,6 +1520,47 @@ begin {$ENDIF} 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; var TempVersion : uint64; diff --git a/source/uCEFTypes.pas b/source/uCEFTypes.pas index fa05c8bb..f78d87c1 100644 --- a/source/uCEFTypes.pas +++ b/source/uCEFTypes.pas @@ -475,6 +475,7 @@ type asUnloaded, asErrorMissingFiles, asErrorDLLVersion, + asErrorWindowsVersion, asErrorLoadingLibrary, asErrorInitializingLibrary, asErrorExecutingProcess); diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index f49e4e27..a452cd97 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 479, + "InternalVersion" : 480, "Name" : "cef4delphi_lazarus.lpk", "Version" : "112.2.9" }