salvadordf / WebView4Delphi

WebView4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows.
https://www.briskbard.com/forum/
MIT License
262 stars 54 forks source link

Prevent of use on WindowsXP (Delphi2010) #63

Closed mark-lobanov closed 1 month ago

mark-lobanov commented 1 month ago

Hello

Please, compile this code and run in Windows XP The following error occurred, try...except does not help I tested it with Delphi 2010

program test;

{$APPTYPE CONSOLE}

uses
  IOUtils,
  SysUtils,
  dxCore, // DevExpress library for function IsWinSevenOrLater
  uWVLoader;

procedure InitWebView2;
begin
  if IsWinSevenOrLater  // Validation from DevExpress library, you can replace with False
  then begin
    Writeln('Yes, is WinSevenOrLater');
    GlobalWebView2Loader := TWVLoader.Create(nil);

    if GlobalWebView2Loader.InstalledRuntimeVersion <> EmptyStr then begin
      GlobalWebView2Loader.UserDataFolder := TPath.Combine(ExtractFilePath( ParamStr(0) ), 'CustomCache');
      GlobalWebView2Loader.AllowRunningInsecureContent := True;
      GlobalWebView2Loader.Language := 'uk-UA';
      GlobalWebView2Loader.StartWebView2;
    end else
      FreeAndNil( GlobalWebView2Loader );
  end else begin
    Writeln('No, maybe WinXP');
    GlobalWebView2Loader := nil;
  end;
end;

begin
  InitWebView2;

  if Assigned( GlobalWebView2Loader ) then
    GlobalWebView2Loader.Free;
end.

image

salvadordf commented 1 month ago

Google announced that they would drop Windows XP support for Chrome in 2015.

Microsoft also announced that WebView2 would drop Windows 7, 8, 8.1 support.

The function in the error message is only available in Windows 7 or newer.

You need to use Windows 10, 11 or newer with WebView4Delphi.

salvadordf commented 1 month ago

Use OldCEF4Delphi if you really need to embed a browser in Windows XP.

mark-lobanov commented 1 month ago

@salvadordf Thanks for the Microsoft links, I read this info before.

Maybe I didn't formulate the problem correctly. I want to disable WebView initialization on Windows younger than Windows 7. The rest of the program code should work.

The test project ^^^ is a part of real program code.

mark-lobanov commented 1 month ago

I think problem in uWVLoaderInternal.pas

{$IFNDEF DELPHI16_UP}
function GetCurrentProcessExplicitAppUserModelID(var AppID: LPWSTR): HRESULT; stdcall; external 'shell32' name 'GetCurrentProcessExplicitAppUserModelID';
{$ENDIF}

I compiled example in Delphi 2010 and this external declaration also was compiled and linked.

When I ran the example in Windows XP I got an error because no such function exists in shell32.dll on Windows XP.

If I compile the example in Delphi Tokyo and run it on Windows XP, the error does not occur !

Unfortunately I have to use Delphi 2010 for this legacy project ((

salvadordf commented 1 month ago

Sorry for the confusion. Please download WebView4Delphi again from GitHub. The Windows 7 dependency has been removed.

mark-lobanov commented 1 month ago

Thank you, it works fine