Hi,
unit Unit42;
interface
uses
Windows, System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
type
TForm42 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form42: TForm42;
implementation
{$R *.fmx}
const
{$IFDEF WIN64}
CoreWebView2DLL = 'WebView2Loader_x64.dll';
{$ELSE}
CoreWebView2DLL = 'WebView2Loader_x86.dll';
{$ENDIF}
var
GetAvailableCoreWebView2BrowserVersionString: function(browserExecutableFolder: PWideChar; versioninfo: PPWideChar): HRESULT; stdcall;
procedure TForm42.FormCreate(Sender: TObject);
var
v: PWideChar;
h: THandle;
begin
h := LoadLibrary(CoreWebView2DLL);
if (h = 0) then
begin
Log.d('WebView2 Loader DLLs not properly installed');
Exit;
end;
try
{$IFDEF LCLLIB}Pointer({$ENDIF}GetAvailableCoreWebView2BrowserVersionString{$IFDEF LCLLIB}){$ENDIF} := GetProcAddress(h, 'GetAvailableCoreWebView2BrowserVersionString');
v := '';
if Assigned(GetAvailableCoreWebView2BrowserVersionString) then
begin
GetAvailableCoreWebView2BrowserVersionString(nil, @v);
//edge detected with version number:
Log.d('edge chromium is found: ' + v);
end
else
Log.d('edge chromium could not be found');
//edge could not be found
finally
FreeLibrary(h);
end;
end;
end.
awesome, thanks for the idea! I was able to figure out another way .. but it involved changing the source code of FMX.TMSWebBrowser.Win.
Great, If you want you can also share your idea
{$IFDEF MSWINDOWS}
var si:IInterface := FacebookLoginForm.WebBrowser2.GetWebBrowserInstance;
if not Assigned(si) then
begin
//showmessage('no chrome');
EdgeInfoForm.ShowModal; //this is a simple form with a label component explaining where to download the edge browser to the user
exit;
end;
{$ENDIF}
{$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF}
{$IFDEF MSWINDOWS}
procedure CheckEdgeBrowser;
{$ENDIF}
{$IFDEF MSWINDOWS}
GetAvailableCoreWebView2BrowserVersionString: function(browserExecutableFolder: PWideChar; versioninfo: PPWideChar): HRESULT; stdcall;
{$ENDIF}
{$IFDEF MSWINDOWS}
procedure TMainForm.CheckEdgeBrowser;
var
v: PWideChar;
h: THandle;
edgeFound:boolean;
begin
edgeFound := true;
h := LoadLibrary(CoreWebView2DLL);
if (h = 0) then
begin
showmessage('WebView2 Loader DLLs not properly installed');
Application.Terminate;
Halt;
end;
try
{$IFDEF LCLLIB}Pointer({$ENDIF}GetAvailableCoreWebView2BrowserVersionString{$IFDEF LCLLIB}){$ENDIF} := GetProcAddress(h, 'GetAvailableCoreWebView2BrowserVersionString');
v := '';
if Assigned(GetAvailableCoreWebView2BrowserVersionString) then
begin
GetAvailableCoreWebView2BrowserVersionString(nil, @v);
if v = '' then edgeFound := false
else edgeFound := true;
end
else edgeFound := false;
//finally, show my custom instructions on how to install the edge chromimum browser
if not edgeFound then
begin
Application.CreateForm(TEdgeInfoForm, EdgeInfoForm);
EdgeInfoForm.ShowModal;
Application.Terminate;
Halt; //I know this is not good to do, but it seems to work for my particular app to stop further code being executed
end;
finally
FreeLibrary(h);
end;
end;
{$ENDIF}
{$IFDEF MSWINDOWS}CheckEdgeBrowser;{$ENDIF}
oops .. forgot to include the dll code in step 3
const
{$IFDEF WIN64}
CoreWebView2DLL = 'WebView2Loader_x64.dll';
{$ELSE}
CoreWebView2DLL = 'WebView2Loader_x86.dll';
{$ENDIF}
Hi,
Thank you for the input, we might incorporate this as a class procedure that returns a type value or boolean, to know if the setup of the browser is correct or not. The code sample you posted is really helpful, thanks!!
I am running Windows Server 2008 R2, with Edge+Chromium installed. I used the 2nd set of steps. GetAvailableCoreWebView2BrowserVersionString(nil, @v);
always sets v = nil
. I have tried with Edge set as the default browser and Firefox set as the default browser. The outcome is the same. I also tried running on Windows 10 v2004 with Edge+Chromium installed. It behaves the same as WinSvr2008R2. If I ignore the check and just create the TTMSFMCWebBrowser
at runtime, it will load web pages using Edge. So The TMS control finds Edge. However, I too need to verify Edge is installed before the end-user loads a web page.
Any suggestions on how to get GetAvailableCoreWebView2BrowserVersionString(nil, @v);
to properly set v
?
I see now, by tracing through VCL.TMSFNCWebBrowser.Win
, that v = nil
either means it is not installed or the stable
version is installed. The next step is to query the registry HKCU\Software\Microsoft\Edge\BLBeacon
and read the value version
to get the installed version of Edge. It makes sense now what I need to do...
Hi James, My apologies for the late answer. Your second answer is correct. I hope Microsoft will add versioning or at least allow for proper detection of the stable version.