The MASM Forum

Projects => Poasm => Pelle's C compiler and tools => Topic started by: TimoVJL on November 26, 2023, 09:51:24 PM

Title: WebView2 test
Post by: TimoVJL on November 26, 2023, 09:51:24 PM
Simple WebView2 test with static client class

WebView2 runtime download (https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section)

Distribute your app and the WebView2 Runtime (https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution)

This way it started:
Unable to make it work in pure C (com_ptr is apparently mandatory but it should not be) (https://github.com/MicrosoftEdge/WebView2Feedback/issues/1124)
Title: Re: WebView2 test
Post by: jj2007 on November 26, 2023, 11:58:09 PM
Windows 10, with Ms Edge as default browser:
I tried the exe, but it says it needs the runtime.
Then I tried installing the runtime, but it says won't work as it is already installed.
 :rolleyes:
Title: Re: WebView2 test
Post by: TimoVJL on November 27, 2023, 12:04:21 AM
Quote from: jj2007 on November 26, 2023, 11:58:09 PMWindows 10, with Ms Edge as default browser:
I tried the exe, but it says it needs the runtime.
Then I tried installing the runtime, but it says won't work as it is already installed.
 :rolleyes:
Do you have WebView2Loader.dll already in a your system ?
Title: Re: WebView2 test
Post by: Biterider on November 27, 2023, 02:03:09 AM
Hi Timo
Thank you for your sample application.  :thumbsup:

The installation of the RT also fails, similar to JJ's attempt, but I discovered that the WebView2Loader.dll file exists several times on my system. I took the latest version and copied it to your files and presto, it displays our forum WebSite... cool  :cool:


Biterider
Title: Re: WebView2 test
Post by: TimoVJL on November 27, 2023, 02:47:05 AM
Thanks Bitrider,
An example was based from sourcecode, that can been seen from links, so my part was quite small.
Title: Re: WebView2 test
Post by: Biterider on November 27, 2023, 05:26:21 AM
Hi Timo
I have looked around in the source code and the most difficult part is the COM interfaces, but everything can be done in assembler too.
If I find some time, I will do it.

Biterider
Title: Re: WebView2 test
Post by: jj2007 on November 27, 2023, 11:12:32 AM
Quote from: Biterider on November 27, 2023, 02:03:09 AMI discovered that the WebView2Loader.dll file exists several times on my system

Where did you find these files? I can't find any on my Win10 machine :sad:
Title: Re: WebView2 test
Post by: TimoVJL on November 27, 2023, 11:59:50 AM
One link for WebView2Loader.dll and header and libs ...

Microsoft.Web.WebView2 (https://www.nuget.org/packages/Microsoft.Web.WebView2)

7-zip can open it.

WebView2Test1 open DeepL translator page

In WebView2h_min.zip is reduced WebView2.h for faster compiling
Title: Re: WebView2 test
Post by: jj2007 on November 27, 2023, 09:04:03 PM
Quote from: TimoVJL on November 27, 2023, 11:59:50 AMOne link for WebView2Loader.dll and header and libs ...

Microsoft.Web.WebView2 (https://www.nuget.org/packages/Microsoft.Web.WebView2)

dotnet add package Microsoft.Web.WebView2 --version 1.0.2151.40
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from: https://aka.ms/dotnet-download (https://aka.ms/dotnet-download)
Title: Re: WebView2 test
Post by: TimoVJL on November 27, 2023, 09:14:06 PM
Just download that microsoft.web.webview2.1.0.2151.40.nupkg from Download package  (7.57 MB)
and use 7-Zip

Direct link:
https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/1.0.2151.40 (https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/1.0.2151.40)

WebView2Loader.dlls are in
\runtimes\win-x86\native\
\runtimes\win-x64\native\
folders

It is a WebView SDK
Title: Re: WebView2 test
Post by: jj2007 on November 27, 2023, 09:40:24 PM
Yep, that worked :thumbsup:

Your exe loads the Masm forum, great.

To build it, I tried (successfully) \masm32\bin\polib.exe /OUT:WebView2Loader.lib /MACHINE:x86 WebView2Loader.dll

However, polink complains:
POLINK: error: Unresolved external symbol '_CreateCoreWebView2EnvironmentWithOptions@16' - referenced from '\Masm32\Members\Timo\Webview2\WebView2Test.obj'.

If I comment out that call in line 13, it builds and runs :thumbsup:
Title: Re: WebView2 test
Post by: TimoVJL on November 27, 2023, 11:44:01 PM
POLIB /DEF:WebView2Loader.def /OUT:WebView2Loader.lib /MACHINE:x86

LIBRARY WebView2Loader.dll
EXPORTS
_CompareBrowserVersions@12 = CompareBrowserVersions
_CreateCoreWebView2Environment@4 = CreateCoreWebView2Environment
_CreateCoreWebView2EnvironmentWithOptions@16 = CreateCoreWebView2EnvironmentWithOptions
_GetAvailableCoreWebView2BrowserVersionString@8 = GetAvailableCoreWebView2BrowserVersionString
x64
POLIB /DEF:WebView2Loader.def /OUT:WebView2Loader.lib /MACHINE:x64
LIBRARY WebView2Loader.dll
EXPORTS
CompareBrowserVersions
CreateCoreWebView2Environment
CreateCoreWebView2EnvironmentWithOptions
GetAvailableCoreWebView2BrowserVersionString
EDIT: example with cl -Fa assembler output
Title: Re: WebView2 test
Post by: TimoVJL on November 30, 2023, 01:35:26 AM
Have anyone tried several times app running in same time with same site like DeepL ?
Sometimes DeepL warns about too many sessions ?

DeepL test (https://masm32.com/board/index.php?msg=125417)

EDIT:
Perhaps it happens after over ten sessions in same time.
A red red alert says, that 'Something went wrong, try to reload page (S-1)' or something like that.
Title: Re: WebView2 test
Post by: Vortex on November 30, 2023, 05:01:30 AM
Quote from: TimoVJL on November 30, 2023, 01:35:26 AMHave anyone tried several times app running in same time with same site like DeepL ?
Sometimes DeepL warns about too many sessions ?

Hi Timo,

Your Pelles C example didn't report any warning while visiting DeepL :thumbsup:
Title: Re: WebView2 test
Post by: jorgon on May 23, 2024, 02:33:48 PM
Hi All

Many thanks TimoVJL for the files showing how you implemented WebView2 in C, and in particular the header files and the exe.  Prior to seeing these files, I had got very bogged down trying to decipher the .net stuff.  I was getting quite frustrated because I like to know how things work which is why I like assembler, but I find that stuff quite incomprehensible.  The code is further obscured by the multitude of header files, includes and static libs with no way of knowing which are being used by the code in question.

The exe that you posted allowed me to see how the implementation looks in assembler, and so I was able to create the attached sample, which I note is actually a lot simpler than the old WebBrowser2 implementation.

The attached files create an ordinary window and displays the MASM forum inside.  It relies on one Windows redistributable DLL - WebView2Loader.dll (in this case the 32 bit version).  The call to that DLL kicks everything off as can be seen from the code.

All the code is all in one file (no includes) which makes it easier to follow.

Sorry, it's in GoAsm but obviously could be converted to your favourite assembler.

Cheers

Jeremy
Title: Re: WebView2 test
Post by: TimoVJL on May 23, 2024, 09:25:01 PM
@jorgon
Good, if i was helpful for you.
I check a your code, if i can learn something new in old age.
Title: Re: WebView2 test
Post by: Vortex on May 24, 2024, 05:01:15 AM
Hş Jeremy,

Nice work :thumbsup:
Title: Re: WebView2 test
Post by: NoCforMe on May 24, 2024, 09:42:43 AM
Quote from: jorgon on May 23, 2024, 02:33:48 PMMany thanks TimoVJL for the files showing how you implemented WebView2 in C, and in particular the header files and the exe.
Jeremy, I've only taken a cursory look at your code, but I have to say something here: I don't know if it was your intent or not, but I have to commend you for opening the door and shining daylight on what is normally clear as mud to us assembly programmers, namely the dense forest of a C++ program with its hidden features and other obscure elements.

I'm interested in this, as I am an assembly-only (MASM) programmer at this point and would like to be able to borrow from C++ examples in my own code. This has seemed like a near-impossible task until now. (I've done some GDI+ programming, which is normally only accessible through C++, but I've used the "flat" libraries which allow access through regular Win32 function calls.)

Especially interesting to me are those "methods" you uncovered in this web application, which are really just pointers to functions (yes, regular old callable Win32 functions) in a list of "methods". I think of what you've done here as something like that scene in the Wizard of Oz where the curtain is pulled back to reveal that it's merely a little man behind all the magic.

One thing: can you tell us where you get the C++ header files to extract that info? I'd like to take a look at them myself. Maybe you could post some of them here.
Title: Re: WebView2 test
Post by: jorgon on May 24, 2024, 11:24:26 AM
Hi NoCforMe

Many thanks for your comments and yes I did want to remove the mystery as far as I could. I was not being altruistic - it was for my own purposes, because I'm writing an Email Client in GoAsm to replace Everdesk which is no longer being supported and which keeps freezing on my machine.  Currently, the Email Client I am writing uses WebBrowser2 to display and edit html emails, but that has limited functionality (it can't render base64 images in the email for example).  So I was looking for an alternative.  WebView2 has many more features, but when running it creates a whole load of files and folders (user data files) and I haven't found a way to stop it doing this yet.  When all you want to do is to display or edit an html email you really don't need a history audit!

The trouble is, it always takes me a while to decipher the C++ and C# stuff.  There are others who can read it much better than me, hence TimoVJL's pure C and the exe he provided (which I could disassemble and compare with the C) was the breakthrough I needed. 

As for the header files, I believe for WebView2 there is only one - WebView2.h. One problem is that there are different versions of this file.  The one TimoVJL posted shows the various structures showing the offsets of the "methods" most clearly.  It is 987K and I attach this as a zip file.  The other versions I have seen are 239K and the one which shipped with the WebView2 Runtime which I download from Microsoft was 512K, but they are not so useful. 

Now all these files have the same name which seems to me to be a recipe for disaster if you are constrained by one of the platform development tools and you have the wrong file - no wonder development teams spend half the time configuring the development tools instead of actual programming like assembler programmers can!
Title: Re: WebView2 test
Post by: TimoVJL on May 24, 2024, 04:31:05 PM
I just created header file from WebView2.tlb, as it can be found from NuGet package.

There might be several WebView2.h files around, that are generated in same way.

MS header file is 1836 KB, so not ideal for other programming languages.
Title: Re: WebView2 test
Post by: jorgon on June 11, 2024, 12:48:48 AM
CommWebView2 builds on HelloWebView2.asm to show how it is possible to establish two way communication with the WebView2 browser, and use it as a rich text (html) editor.  It explains the use of Navigate, NavigateToString, ExecuteScript, execCommand, and add_WebMessageReceived.
Sorry it's in GoAsm but could be converted to other languages.
Title: Re: WebView2 test
Post by: morgot on August 06, 2024, 07:40:54 AM
jorgon, thanks for the code.
But why do I need to install some components to make webview2 work? If I already have microsoft edge in Windows. Why doesn't it take webview2 from there, but I need to install something else? How does it work?
Title: Re: WebView2 test
Post by: TimoVJL on August 06, 2024, 09:34:37 PM
WebView2 will be part of windows 10 and 11, so only older versions needs that runtime dll.
I haven't found, when it will be an update to Windows 10.

Delivering the Microsoft Edge WebView2 Runtime to Windows 10 Consumers (https://blogs.windows.com/msedgedev/2022/06/27/delivering-the-microsoft-edge-webview2-runtime-to-windows-10-consumers/)
Title: Re: WebView2 test
Post by: morgot on August 06, 2024, 11:41:40 PM
Quote from: TimoVJL on August 06, 2024, 09:34:37 PMso only older versions needs that runtime dll
OK, but why I can't only copy runtime.dll? Why I need to install all SDK?
Title: Re: WebView2 test
Post by: zedd151 on August 06, 2024, 11:56:08 PM
Quote from: morgot on August 06, 2024, 11:41:40 PMOK, but why I can't only copy runtime.dll? Why I need to install all SDK?
I would venture to guess that there may be some dependencies which would be missing in that scenario. The .dll might depend on other parts of the SDK. But that is only a guess.
Title: Re: WebView2 test
Post by: TimoVJL on August 07, 2024, 04:06:12 AM
SDK is for developers, and who share that dll with their application.
No installations, just one dll in same folder as application, if edge was installed earlier.
Stay tuned  :smiley:

Implementation of WebView2 (https://masm32.com/board/index.php?topic=11965.msg130890#msg130890)