Jump to content

Microsoft Edge - WebView2, embed web code in your native application


mLipok
 Share

Recommended Posts

Comming new features:

https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp#101414-prerelease

btw.
Did you notice that SDK is already automatically installed with Windows Updates service ?
image.png.eb3e09656553e25c4b9f7145671a95b2.png
 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 3 months later...

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 4 weeks later...

https://github.com/MicrosoftEdge/WebView2Announcements/issues/61

Quote

We have published API reference for window.chrome.webview JavaScript APIs which you can use along with native WebView2 APIs to communicate between native code and web code.

Please leave any feedback in our WebView2Feedback repo. Thanks!

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

Thank you for the EnvSet() usage with WebView2.

I am working on a network program which uses mLipok's AutoIt code and WebView2 in a multi-user environment. However, in a multi-user environment, users cannot share the same cache folder from WebView2. Setting the environment to the user's appData folder fixed the problem as each user now has their own cache for WebView2.

On to the next problem, though they are becoming fewer as I go.

Thanks to mLipok and Krakatoa again!

Link to comment
Share on other sites

Anyone know how to set:
CoreWebView2Controller.DefaultBackgroundColor

I've tried (but it doesn't work):
$oCoreWebView2.DefaultBackgroundColor = 0x00000000

The default background color is white and I want to set it to black. I was able to make a hack to load a simple web page with a black background, but it is not exactly what I wanted to do. Works ... but if I could set the DefaultBackgroundColor it would be better.

I'm certain others may be interested in the ability to set the default color of the controller.

Link to comment
Share on other sites

Well, I answered my own question. Just as you can set the default data folder with SetEnv(), you can also set the default background color of WebView2 with SetEnv(). However, all calls to SetEnv() must be made BEFORE the WebView2 controller is initialized.

To set the window to black:
SetEnv( "WEBVIEW2_DEFAULT_BACKGROUND_COLOR", "FF000000" )

Format of the color is: AARRGGBB in hex format where AA is the transparency of the window. When AA=FF the WebView2 window will be fully opaque and when AA=00 the WebView2 window will be fully transparent.

Link to comment
Share on other sites

20 hours ago, Clifton said:

mLipok's AutoIt code and WebView2

I think we misunderstand.
It is @LarsJ code and it is only my disscussion I mean I started this discussion.

Unless you mean my some other code.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I am grateful to the ALL the very intelligent programmers who started merging WebView2 and AutoIT as well to those who have contributed in other ways to making this work by posting to this forum.

Another environment variable that works with WebView2 and AutoIT allows you to run your content locally and make requests to an Internet site for data. I needed this in my application or I would've had to exchange data using the $oCoreWebView2.ExecuteScript() to have AutoIT handle the passing of data to and from my website database. Basically, this allows CORS in the WebView2 viewer.

Here is the environment property the makes POSTING data work:
SetEnv( "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-web-security" )

Remember to set the environment property BEFORE the WebView2 controller is intialized.

Edited by Clifton
Link to comment
Share on other sites

  • 2 weeks later...

Perhaps someone can help with this related problem.
I need to set the IsMuted property to True for the WebView2 viewer.

I've tried $oCoreWebView2.IsMuted = True . . . but it does not work.
I've tried $oCoreWebView2Controller.IsMuted = True . . . but that doesn't work either.
I've tried other variations with .IsMuted = True and they all are ineffective at muting the WebView2 component.

From what I've read, the property to set is IsMuted, but I don't know how to set it and on which object in the WebView2 scripts.

I can mute and unmute using JavaScript code in the application, but sometimes it would be better and more efficient to just mute the entire applicaiton.

Any help would be appreciated.

Link to comment
Share on other sites

  • 4 weeks later...

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/print?tabs=dotnetcsharp

Quote
PrintToPdf Silently prints the current top-level document in the WebView2 to a PDF file. You can use this to build your own code to print the PDF file.
PrintToPdfStream Silently prints the current top-level document in the WebView2 to a PDF stream. You can use this to build your own code to print the PDF.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.printtopdfasync?view=webview2-dotnet-1.0.1823.32#microsoft-web-webview2-core-corewebview2-printtopdfasync

 

https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2printsettings?view=webview2-dotnet-1.0.1823.32

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 2 weeks later...

I found this:

CoreWebView2.CapturePreviewAsync Method (Microsoft.Web.WebView2.Core) | Microsoft Learn

I added it to WV2Interfaces.au3, which seems to work but I don't know if this is the correct $tag

Global Const $dtag_ICoreWebView2Environment = _
    "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _
    "CreateWebResourceResponse hresult();" & _
    "get_BrowserVersionString hresult();" & _
    "add_NewBrowserVersionAvailable hresult();" & _
    "remove_NewBrowserVersionAvailable hresult();" & _
    "CapturePreviewAsync hresult(byte;ptr);"

which requires imageStream from class Stream Stream Class (System.IO) | Microsoft Learn but I don't know how to add it.

 

Any idea?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

After reading through this thread, you guys have done an amazing job on this! I am working on a project that just entails opening a webpage I have the rest scripted to automate I just call my WebView2 executable. this work great! However, when I run my WebView2 executable it has the pop-up saying the website says this... and every time it goes to a new redirect it pops up again with the new URL. I know just enough about scripting to be dangerous. But if I could get it not to do the pop-ups, I believe my script would work as intended!
Thank you so much for all your hard work on this!!

image.png.1c308fb1aa478b9f57890ef39c95c6cb.png

Link to comment
Share on other sites

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

5 minutes ago, mLipok said:

please let us know when you will find the right solution.

I mean if you find solution, please share you experience, knowledge, or even example in AutoIt.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 4 weeks later...
On 6/16/2023 at 8:34 PM, UEZ said:

I found this:

CoreWebView2.CapturePreviewAsync Method (Microsoft.Web.WebView2.Core) | Microsoft Learn

I added it to WV2Interfaces.au3, which seems to work but I don't know if this is the correct $tag

Global Const $dtag_ICoreWebView2Environment = _
    "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _
    "CreateWebResourceResponse hresult();" & _
    "get_BrowserVersionString hresult();" & _
    "add_NewBrowserVersionAvailable hresult();" & _
    "remove_NewBrowserVersionAvailable hresult();" & _
    "CapturePreviewAsync hresult(byte;ptr);"

which requires imageStream from class Stream Stream Class (System.IO) | Microsoft Learn but I don't know how to add it.

 

Any idea?

Hi @UEZ,
The link you posted refers to the WebView2's .NET environment.
the "environment" created by larsj here is instead based on a WIN32 WebView COM environment, and the link for that method in our case would look like this:
https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.1901.177#capturepreview.
Following the information posted by @LarsJ in this topic, and imitating by analogy the settings related to the .ExecuteScript method which is working, I attempted to implement that CapturePreview method (lines 440 - 477 in WV2Interfaces_mod.au3), but surely I'm doing something wrong as the script terminates with this error:
AutoIt3.exe ended.rc:-1073741819
Maybe I'm not adapting the parameters correctly from these two code snippets in the WebView2.h file to line 86 and line 443 in WV2Interfaces_mod.au3

         virtual HRESULT STDMETHODCALLTYPE CapturePreview(
             /* [in] */ COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT imageFormat,
             /* [in] */ IStream *imageStream,
             /* [in] */ ICoreWebView2CapturePreviewCompletedHandler *handler) = 0;

and this:

     {
     public:
         virtual HRESULT STDMETHODCALLTYPE Invoke(
             /* [in] */ HRESULT errorCode) = 0;
     }

i also think that the parameter of type "stream" the way i tried to implement it could cause problems...(?)
i implemented the callback functions too, but the whole thing doesn't work

for testing you can simply download this compressed file created by Larsj which contains the basic environment needed to run WebView2.
It consists of 2 folders to be extracted in a path of your choice where you have write rights:
Examples
Includes

so to do some testing you can use the following two draft listings, which I also used for testing:

  • put the below WebView2Draft.au3 script inside the Examples folder
  • put the below WV2Interfaces_mod.au3 script inside the Includes folder

when running the WebView2Draft.au3 listing an AutoIt GUI is generated with an embedded WebView2 control where a simple HTML page is displayed.
clicking the ExecuteScript button, the system works and sends the two addends present in the input boxes of AutoIt to javascript. The result of the calculation performed by javascript is then returned to AutoIt using the CallBack function.
While the CapturePreview button (lines from 78 to 95) doesn't work and sends the script into error.
I hope someone understands where the problem is and manages to make it work

sorry if this is a bit in draft form, but it's just experimenting material.

Thanks

WebView2Draft.au3 put this in the Examples folder

#AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_UseX64=y

Opt("MustDeclareVars", 1)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPICom.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>

Global Const $STGM_READWRITE = 2, $STGM_CREATE = 0x00001000

Global $hGui
Global $idParam1, $vParam1, $idParam2, $vParam2, $idLabelResult
Global $hStream ; handle to a file to write screenshot to
Global $COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG = 0 ; format of file PNG
Global $sScrrenShot_Path = 'c:\temp\WebView2_Screenshot.png'

; Project includes
#include "..\Includes\WV2Interfaces_mod.au3"

WebView2()

Func WebView2()

    ; Create WebView2 GUI
    $hGui = GUICreate("WebView2 Sample", 650, 350, -1, -1, $WS_OVERLAPPEDWINDOW)

    ; Create AutoIt controls
    Local $idButton = GUICtrlCreateButton("ExecuteScript", 10, 250, 170, 40)
    $idParam1 = GUICtrlCreateInput(5, 200, 250, 50, 40)
    GUICtrlCreateLabel('+', 252, 260, 10)
    $idParam2 = GUICtrlCreateInput(2, 260, 250, 50, 40)
    GUICtrlCreateLabel('=', 312, 260, 10)
    $idLabelResult = GUICtrlCreateLabel("", 320, 250, 170, 40)

    Local $idWebScreenShot = GUICtrlCreateButton("CapturePreview", 10, 300, 170, 40)

    ; Initialize COM
    _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED)

    ; Create callback interface and functions
    CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate(False)
    ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed

    ; Create callback interface and functions
    CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate(False)

    ; Create callback interface and functions
    CoreWebView2ExecuteScriptCompletedHandlerCreate(False)

    ; Create callback interface and functions
    CoreWebView2CapturePreviewCompletedHandlerCreate(False) ;

    ; DllCall CreateCoreWebView2EnvironmentWithOptions
    Local $hWebView2Loader = DllOpen(@AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll")
    Local $aRet = DllCall($hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", @ScriptDir, _
            "ptr", Null, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler)
    If @error Or $aRet[0] Then Return ConsoleWrite("CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF)
    ConsoleWrite("CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF)

    ; Show WebView2 GUI
    GUISetState(@SW_SHOW)

    ; Loop
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE
                Local $tRect = _WinAPI_GetClientRect($hGui)
                $oCoreWebView2Controller.put_Bounds($tRect)

            Case $idButton ; ExecuteScript
                $vParam1 = GUICtrlRead($idParam1)
                $vParam2 = GUICtrlRead($idParam2)

                $oCoreWebView2.ExecuteScript("calc(" & $vParam1 & "," & $vParam2 & ");", $pCoreWebView2ExecuteScriptCompletedHandler)
                ; ConsoleWrite(" ==> " & $oCoreWebView2.get_BrowserProcessId & " <==" & @CRLF)
                ; Forces CoreWebView2ExecuteScriptCompletedHandler_Invoke() below to be executed

            Case $idWebScreenShot ; CapturePreview
                ; create a stream on a file [By the great UEZ! :) ]
                FileDelete($sScrrenShot_Path)
                $hStream = _WinAPI_SHCreateStreamOnFileEx($sScrrenShot_Path, BitOR($STGM_READWRITE, $STGM_CREATE), $FILE_ATTRIBUTE_NORMAL, True)

                ConsoleWrite("-Debug stream --: " & @error & @TAB & VarGetType($hStream) & @TAB & $hStream & @TAB & VarGetType($oCoreWebView2) & @CRLF)
                ; load a web page
                ; $oCoreWebView2.Navigate("https://www.autoitscript.com")
                ; MsgBox(0, '', 'Pause to give time to load page')
                ConsoleWrite("------------------" & @CRLF)

                $oCoreWebView2.CapturePreview($COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG, $hStream, $pICoreWebView2CapturePreviewCompletedHandler)
                ; above call Forces in turn CoreWebView2CapturePreviewCompletedHandler_Invoke() callback function below to be executed after screenshot is taken
                ; MsgBox(0, '', 'Pause post screenshot')
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    ; Cleanup
    CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete()
    CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete()
    CoreWebView2ExecuteScriptCompletedHandlerDelete()
    CoreWebView2CapturePreviewCompletedHandlerDelete()
    DllClose($hWebView2Loader)
EndFunc   ;==>WebView2

; Copied from WV2Interfaces.au3
; Executed automatically when the callback interface is created
Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke($pSelf, $long, $ptr)     ; Ret: long  Par: long;ptr*
    ConsoleWrite("CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF)

    ; Create CoreWebView2Environment object
    $oCoreWebView2Environment = ObjCreateInterface($ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment)
    ConsoleWrite("IsObj( $oCoreWebView2Environment ) = " & IsObj($oCoreWebView2Environment) & @CRLF & @CRLF)

    ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI
    $oCoreWebView2Environment.CreateCoreWebView2Controller($hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler)
    ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed

    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $long
EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke

; Copied from WV2Interfaces.au3
; Executed as a consequence of $oCoreWebView2Environment.CreateCoreWebView2Controller() above
Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke($pSelf, $long, $ptr)     ; Ret: long  Par: long;ptr*
    ConsoleWrite("CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF)

    ; Create CoreWebView2Controller object
    $oCoreWebView2Controller = ObjCreateInterface($ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller)
    ConsoleWrite("IsObj( $oCoreWebView2Controller ) = " & IsObj($oCoreWebView2Controller) & @CRLF)
    $oCoreWebView2Controller.AddRef() ; Prevent the object from being deleted when the function ends

    ; Set bounds for the CoreWebView2 object
    Local $tRect = _WinAPI_GetClientRect($hGui)
    $oCoreWebView2Controller.put_Bounds($tRect)

    ; Create CoreWebView2 object
    $oCoreWebView2Controller.get_CoreWebView2($pCoreWebView2)
    $oCoreWebView2 = ObjCreateInterface($pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2)
    ConsoleWrite("IsObj( $oCoreWebView2 ) = " & IsObj($oCoreWebView2) & @CRLF & @CRLF)

    ; Navigate to web page
    $oCoreWebView2.NavigateToString(_GetPage())

    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $long
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke

; Copied from WV2Interfaces.au3
; Executed as a consequence of $oCoreWebView2.ExecuteScript() above
Func CoreWebView2ExecuteScriptCompletedHandler_Invoke($pSelf, $long, $wstr)   ; Ret: long  Par: long;wstr
    ConsoleWrite("CoreWebView2ExecuteScriptCompletedHandler_Invoke()" & @CRLF)
    ConsoleWrite("$long = " & $long & @TAB & "$wstr = " & $wstr & @CRLF & @CRLF)
    ControlSetText('', '', $idLabelResult, $wstr)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandler_Invoke

Func CoreWebView2CapturePreviewCompletedHandler_Invoke($pSelf, $iErrorCode)   ; Ret: dword
    ConsoleWrite("CoreWebView2CapturePreviewCompletedHandler_Invoke()" & @CRLF)
    ConsoleWrite("CapturePreview returned Error code: " & $iErrorCode & @CRLF)
    Return 0     ; For AddRef/Release
    #forceref $pSelf, $iErrorCode
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandler_Invoke

Func _GetPage()
    Local $sSource = ""
    $sSource &= "<!DOCTYPE html>" & @CRLF
    $sSource &= "<html>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "<head>" & @CRLF
    $sSource &= "  <title>Our Company</title>" & @CRLF
    $sSource &= "<SCRIPT>" & @CRLF
    $sSource &= "function calc(x,y){" & @CRLF
    $sSource &= "return x + y;" & @CRLF
    $sSource &= "}" & @CRLF
    $sSource &= "</SCRIPT>" & @CRLF
    $sSource &= "</head>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "<body>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "  <h1>Welcome to WebView2 embedded in AutoIt</h1> " & @CRLF
    $sSource &= "  <h2>Web Site Main Ingredients:</h2>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "  <p>A web Page (HTML) embedded in an AutoIt GUI</p>" & @CRLF
    $sSource &= "  <p>Computer Code (JavaScript) embedded in the web page</p>" & @CRLF
    $sSource &= "  <p>Execute javascript from AutoIt (AutoIt - Javascript interaction)</p>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "</body>" & @CRLF
    $sSource &= "" & @CRLF
    $sSource &= "</html> " & @CRLF
    Return $sSource
EndFunc   ;==>_GetPage

; https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-shcreatestreamonfileex
Func _WinAPI_SHCreateStreamOnFileEx($sFile, $grfMode, $dwAttributes, $fCreate)     ; By UEZ
    ; https://www.autoitscript.com/forum/topic/204362-microsoft-edge-webview2-embed-web-code-in-your-native-application/?do=findComment&comment=1523541
    Local $iLen = StringLen($sFile), $tFile = DllStructCreate("wchar szFile[" & $iLen & "]")
    $tFile.szFile = $sFile
    Local $aResult = DllCall("Shlwapi.dll", "long", "SHCreateStreamOnFileEx", "struct*", $tFile, "dword", $grfMode, "dword", $dwAttributes, "bool", $fCreate, "ptr", Null, "ptr*", 0)
    If $aResult[0] Or @error Then Return SetError(1, 0, 0)
    Return $aResult[6]
EndFunc   ;==>_WinAPI_SHCreateStreamOnFileEx

 

WV2Interfaces_mod.au3 put this in the Includes folder

#include-once

#include "ObjectFromTag.au3"

; Globals for callback interfaces

; for Environment creation
; ------------------------
Global _
        $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ ; ..... result returned by ObjectFromTag
        $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ; ........ Interface struct (DllStruct)


; for controller creation
; -----------------------
Global _
        $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ ; ..... <-- result returned by ObjectFromTag (an object or a pointer to the object)
        $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler ; ........ <-- Interface struct (DllStruct)

; for ExecuteScript creation
; --------------------------
Global _
        $pCoreWebView2ExecuteScriptCompletedHandler, _ ; ..... <-- result returned by ObjectFromTag (an object or a pointer to the object)
        $tCoreWebView2ExecuteScriptCompletedHandler ; ........ <-- Interface struct (DllStruct)

; for CapturePreview creation
; ---------------------------
Global _
        $pICoreWebView2CapturePreviewCompletedHandler, _
        $tICoreWebView2CapturePreviewCompletedHandler


; NavigationStarting
; ------------------
Global _
        $pCoreWebView2NavigationStartingEventHandler, _
        $tCoreWebView2NavigationStartingEventHandler

; WebMessageReceived
; ------------------
Global _
        $pCoreWebView2WebMessageReceivedEventHandler, _
        $tCoreWebView2WebMessageReceivedEventHandler

; --- ICoreWebView2 interface ---

Global $oCoreWebView2, $pCoreWebView2

Global Const $sIID_ICoreWebView2 = "{76ECEACB-0462-4D94-AC83-423A6793775E}"
; https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2
; https://mam-mam.net/delphi/tedgebrowser_webview2.html

; https://docs.rs/webview2-sys/latest/src/webview2_sys/lib.rs.html
; https://stackoverflow.com/questions/2230758/what-does-lpcwstr-stand-for-and-how-should-it-be-handled

; https://docs.rs/webview2-sys/latest/webview2_sys/index.html

Global Const $dtag_ICoreWebView2 = _
        "get_Settings hresult(ptr*);" & _
        "get_Source hresult(wstr*);" & _ ; ok
        "Navigate hresult(wstr);" & _
        "NavigateToString hresult(wstr);" & _
        "add_NavigationStarting hresult(ptr;struct*);" & _
        "remove_NavigationStarting hresult();" & _
        "add_ContentLoading hresult();" & _
        "remove_ContentLoading hresult();" & _
        "add_SourceChanged hresult();" & _
        "remove_SourceChanged hresult();" & _
        "add_HistoryChanged hresult();" & _
        "remove_HistoryChanged hresult();" & _
        "add_NavigationCompleted hresult();" & _
        "remove_NavigationCompleted hresult();" & _
        "add_FrameNavigationStarting hresult();" & _
        "remove_FrameNavigationStarting hresult();" & _
        "add_FrameNavigationCompleted hresult();" & _
        "remove_FrameNavigationCompleted hresult();" & _
        "add_ScriptDialogOpening hresult();" & _
        "remove_ScriptDialogOpening hresult();" & _
        "add_PermissionRequested hresult();" & _
        "remove_PermissionRequested hresult();" & _
        "add_ProcessFailed hresult();" & _
        "remove_ProcessFailed hresult();" & _
        "AddScriptToExecuteOnDocumentCreated hresult(wstr;ptr);" & _
        "RemoveScriptToExecuteOnDocumentCreated hresult();" & _
        "ExecuteScript hresult(wstr;ptr);" & _ ; ok ; LPCWSTR javaScript, ICoreWebView2ExecuteScriptCompletedHandler *handler
        "CapturePreview hresult(int32;ptr;ptr);" & _ ; COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT imageFormat, IStream *imageStream, ICoreWebView2CapturePreviewCompletedHandler *handler
        "Reload hresult(none);" & _ ; ok ; * !!! you have to pass an argument anyway in the function call, or error occurs (?strange but true)
        "PostWebMessageAsJson hresult();" & _
        "PostWebMessageAsString hresult();" & _
        "add_WebMessageReceived hresult(ptr;struct*);" & _
        "remove_WebMessageReceived hresult();" & _
        "CallDevToolsProtocolMethod hresult();" & _
        "get_BrowserProcessId hresult(UINT*);" & _ ; ok
        "get_CanGoBack hresult(BOOL*);" & _ ; ok
        "get_CanGoForward hresult(BOOL*);" & _ ; ok
        "GoBack hresult(none);" & _ ; ok ; * !!! you have to pass an argument anyway in the function call, or error occurs (?strange but true)
        "GoForward hresult(none);" & _ ; ok ; !!! you have to pass an argument anyway in the function call, or error occurs (?strange but true)
        "GetDevToolsProtocolEventReceiver hresult();" & _
        "Stop hresult();" & _
        "add_NewWindowRequested hresult();" & _
        "remove_NewWindowRequested hresult();" & _
        "add_DocumentTitleChanged hresult();" & _
        "remove_DocumentTitleChanged hresult();" & _
        "get_DocumentTitle hresult(wstr*);" & _ ; ok
        "AddHostObjectToScript hresult();" & _
        "RemoveHostObjectFromScript hresult();" & _
        "OpenDevToolsWindow hresult();" & _
        "add_ContainsFullScreenElementChanged hresult();" & _
        "remove_ContainsFullScreenElementChanged hresult();" & _
        "get_ContainsFullScreenElement hresult(BOOL*);" & _ ; ok
        "add_WebResourceRequested hresult();" & _
        "remove_WebResourceRequested hresult();" & _
        "AddWebResourceRequestedFilter hresult();" & _
        "RemoveWebResourceRequestedFilter hresult();" & _
        "add_WindowCloseRequested hresult();" & _
        "remove_WindowCloseRequested hresult();"

; --- ICoreWebView2Settings interface ---

Global $oCoreWebView2Settings, $pCoreWebView2Settings
Global Const $sIID_ICoreWebView2Settings = "{E562E4F0-D7FA-43AC-8D71-C05150499F00}"
Global Const $dtag_ICoreWebView2Settings = _
        "get_IsScriptEnabled hresult();" & _
        "put_IsScriptEnabled hresult();" & _
        "get_IsWebMessageEnabled hresult(bool*);" & _
        "put_IsWebMessageEnabled hresult();" & _
        "get_AreDefaultScriptDialogsEnabled hresult();" & _
        "put_AreDefaultScriptDialogsEnabled hresult();" & _
        "get_IsStatusBarEnabled hresult();" & _
        "put_IsStatusBarEnabled hresult();" & _
        "get_AreDevToolsEnabled hresult();" & _
        "put_AreDevToolsEnabled hresult();" & _
        "get_AreDefaultContextMenusEnabled hresult();" & _
        "put_AreDefaultContextMenusEnabled hresult();" & _
        "get_AreHostObjectsAllowed hresult();" & _
        "put_AreHostObjectsAllowed hresult();" & _
        "get_IsZoomControlEnabled hresult();" & _
        "put_IsZoomControlEnabled hresult();" & _
        "get_IsBuiltInErrorPageEnabled hresult();" & _
        "put_IsBuiltInErrorPageEnabled hresult();"

; --- ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler and related interfaces and functions ---

; ICoreWebView2Environment interface
Global $oCoreWebView2Environment
Global Const $sIID_ICoreWebView2Environment = "{B96D755E-0319-4E92-A296-23436F46A1FC}"
Global Const $dtag_ICoreWebView2Environment = _
        "CreateCoreWebView2Controller hresult(hwnd;ptr);" & _
        "CreateWebResourceResponse hresult();" & _
        "get_BrowserVersionString hresult();" & _
        "add_NewBrowserVersionAvailable hresult();" & _
        "remove_NewBrowserVersionAvailable hresult();"

#cs
// *********************************************************************//
// interface: ICoreWebView2Environment
// flag: (0)
// GUID: {B96D755E-0319-4E92-A296-23436F46A1FC}
// *********************************************************************//
  ICoreWebView2Environment = interface(IUnknown)
    ['{B96D755E-0319-4E92-A296-23436F46A1FC}']
    function CreateCoreWebView2Controller(var ParentWindow: _RemotableHandle;
                                          const handler: ICoreWebView2CreateCoreWebView2ControllerCompletedHandler): HResult; stdcall;
    function CreateWebResourceResponse(const Content: IStream; StatusCode: SYSINT;
                                       ReasonPhrase: PWideChar; Headers: PWideChar;
                                       out Response: ICoreWebView2WebResourceResponse): HResult; stdcall;
    function Get_BrowserVersionString(out versionInfo: PWideChar): HResult; stdcall;
    function add_NewBrowserVersionAvailable(const eventHandler: ICoreWebView2NewBrowserVersionAvailableEventHandler;
                                            out token: EventRegistrationToken): HResult; stdcall;
    function remove_NewBrowserVersionAvailable(token: EventRegistrationToken): HResult; stdcall;
  end;
#ce

; ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface
; ----------------------------------------------------------------------------------------------------------------
Global Const $sIID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = "{4E8A3389-C9D8-4BD2-B6B5-124FEE6CC14D}" ; <-- ??? not used

#cs ; from ; https://pkg.go.dev/github.com/zzl/go-webview2/wv2

var IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = syscall.GUID{0x4E8A3389, 0xC9D8, 0x4BD2,
    [8]byte{0xB6, 0xB5, 0x12, 0x4F, 0xEE, 0x6C, 0xC1, 0x4D}}

// 4E8A3389-C9D8-4BD2-B6B5-124FEE6CC14D
var IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = syscall.GUID{0x4E8A3389, 0xC9D8, 0x4BD2,
    [8]byte{0xB6, 0xB5, 0x12, 0x4F, 0xEE, 0x6C, 0xC1, 0x4D}}

#ce ; from ; https://pkg.go.dev/github.com/zzl/go-webview2/wv2
; ----------------------------------------------------------------------------------------------------------------
Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _
        "Invoke hresult(hresult;ptr*);"

; Functions to create and delete the callback interface
;
; first call
; crea l'environment e ne restituisce il "pointer" nella variabile Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler
;                                                                                                         ===========
;
Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate($bPrint = False)
    $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = ObjectFromTag( _
            "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ ; ...... Presents methods/properties with the same prefix name
            $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ ; .. Interface description tag string
            $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ ; ....... Interface struct (DllStruct)
            False, _ ; ............................................................. Return object if True or object pointer if False
            $bPrint _ ; ............................................................ Print information in SciTE console
            ) ;                                                                      Last 2 parameters uses default values
    ;       $bIsUnknown = True, _ ; ................................................ Inherits from the IUnknown interface
    ;       $sIID = "{00000000-0000-0000-C000-000000000046}") ; .................... Last param is IID_IUnknown by default

    If $bPrint Then ConsoleWrite("$pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = " & $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler & @CRLF & @CRLF)

EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate

Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete()
    $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = 0
    DeleteObjectFromTag($tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler)
EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete

; Callback functions

Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite("# invoked -> EnvironmentCompletedHandler_QueryInterface() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)  ; & "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface

Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)  ; & "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef

Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)  ; &("CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release

#cs
Function copied to example code
Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long  Par: long;ptr*
    ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF )
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $long, $ptr
EndFunc
#ce

; --- ICoreWebView2CreateCoreWebView2ControllerCompletedHandler and related interfaces and functions ---

; ICoreWebView2Controller interface
Global $oCoreWebView2Controller
Global Const $sIID_ICoreWebView2Controller = "{4D00C0D1-9434-4EB6-8078-8697A560334F}"
Global Const $dtag_ICoreWebView2Controller = _
        "get_IsVisible hresult();" & _
        "put_IsVisible hresult();" & _
        "get_Bounds hresult();" & _
        (@AutoItX64 ? "put_Bounds hresult(struct*);" : "put_Bounds hresult(struct);") & _
        "get_ZoomFactor hresult();" & _
        "put_ZoomFactor hresult();" & _
        "add_ZoomFactorChanged hresult();" & _
        "remove_ZoomFactorChanged hresult();" & _
        "SetBoundsAndZoomFactor hresult();" & _
        "MoveFocus hresult();" & _
        "add_MoveFocusRequested hresult();" & _
        "remove_MoveFocusRequested hresult();" & _
        "add_GotFocus hresult();" & _
        "remove_GotFocus hresult();" & _
        "add_LostFocus hresult();" & _
        "remove_LostFocus hresult();" & _
        "add_AcceleratorKeyPressed hresult();" & _
        "remove_AcceleratorKeyPressed hresult();" & _
        "get_ParentWindow hresult();" & _
        "put_ParentWindow hresult();" & _
        "NotifyParentWindowPositionChanged hresult();" & _
        "Close hresult();" & _
        "get_CoreWebView2 hresult(ptr*);"

; ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback interface

Global Const $sIID_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler = "{6C4819F3-C9B7-4260-8127-C9F5BDE7F68C}"
Global Const $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler = _
        "Invoke hresult(hresult;ptr*);"

; Functions to create and delete the callback interface
; second call
; create 'controller' in Global $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler
;
Func CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate($bPrint = False)
    $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = ObjectFromTag( _
            "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_", _ ; ...... Presents methods/properties with the same prefix name
            $dtag_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ ; .. Interface description tag string
            $tCoreWebView2CreateCoreWebView2ControllerCompletedHandler, _ ; ....... Interface struct (DllStruct)
            False, _ ; ............................................................ Return object if True or object pointer if False
            $bPrint _ ; ........................................................... Print information in SciTE console
            ) ;                                                                     Last 2 parameters uses default values
    ;       $bIsUnknown = True, _ ; ............................................... Inherits from the IUnknown interface
    ;       $sIID = "{00000000-0000-0000-C000-000000000046}") ; ................... Last param is IID_IUnknown by default

    If $bPrint Then ConsoleWrite("$pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = " & $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate

Func CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete()
    $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = 0
    DeleteObjectFromTag($tCoreWebView2CreateCoreWebView2ControllerCompletedHandler)
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete

; Callback functions

Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite("# invoked -> CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface

Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef

Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release

#cs
Function copied to example code
Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long  Par: long;ptr*
    ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke()" & @CRLF & @CRLF )
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $long, $ptr
EndFunc
#ce

; --- ICoreWebView2NavigationStartingEventHandler and related interfaces and functions ---

; ICoreWebView2NavigationStartingEventArgs interface
Global $oCoreWebView2NavigationStartingEventArgs
Global Const $sIID_ICoreWebView2NavigationStartingEventArgs = "{5B495469-E119-438A-9B18-7604F25F2E49}"
Global Const $dtag_ICoreWebView2NavigationStartingEventArgs = _
        "get_Uri hresult(wstr*);" & _
        "get_IsUserInitiated hresult(bool*);" & _
        "get_IsRedirected hresult(bool*);" & _
        "get_RequestHeaders hresult(ptr*);" & _
        "get_Cancel hresult(bool*);" & _
        "put_Cancel hresult(bool);" & _
        "get_NavigationId hresult(struct*);"

; ICoreWebView2NavigationStartingEventHandler callback interface

Global Const $sIID_ICoreWebView2NavigationStartingEventHandler = "{9ADBE429-F36D-432B-9DDC-F8881FBD76E3}"
Global Const $dtag_ICoreWebView2NavigationStartingEventHandler = _
        "Invoke hresult(ptr*;ptr*);"

; Functions to create and delete the callback interface

Func CoreWebView2NavigationStartingEventHandlerCreate($bPrint = False)
    $pCoreWebView2NavigationStartingEventHandler = ObjectFromTag("CoreWebView2NavigationStartingEventHandler_", $dtag_ICoreWebView2NavigationStartingEventHandler, $tCoreWebView2NavigationStartingEventHandler, False, $bPrint)
    If $bPrint Then ConsoleWrite("$pCoreWebView2NavigationStartingEventHandler = " & $pCoreWebView2NavigationStartingEventHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2NavigationStartingEventHandlerCreate

Func CoreWebView2NavigationStartingEventHandlerDelete()
    $pCoreWebView2NavigationStartingEventHandler = 0
    DeleteObjectFromTag($tCoreWebView2NavigationStartingEventHandler)
EndFunc   ;==>CoreWebView2NavigationStartingEventHandlerDelete

; Callback functions

Func CoreWebView2NavigationStartingEventHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite("# invoked -> CoreWebView2NavigationStartingEventHandler_QueryInterface() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2NavigationStartingEventHandler_QueryInterface

Func CoreWebView2NavigationStartingEventHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2NavigationStartingEventHandler_AddRef() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2NavigationStartingEventHandler_AddRef

Func CoreWebView2NavigationStartingEventHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2NavigationStartingEventHandler_Release() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2NavigationStartingEventHandler_Release

#cs
Function copied to example code
Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long  Par: ptr*;ptr*
    ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF & @CRLF )
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $ptr1, $ptr2
EndFunc
#ce

; --- ICoreWebView2ExecuteScriptCompletedHandler and related interfaces and functions ---

; ICoreWebView2ExecuteScriptCompletedHandler callback interface

Global Const $sIID_ICoreWebView2ExecuteScriptCompletedHandler = "{49511172-CC67-4BCA-9923-137112F4C4CC}"
Global Const $dtag_ICoreWebView2ExecuteScriptCompletedHandler = _
        "Invoke hresult(hresult;wstr);"

; Functions to create and delete the callback interface
Func CoreWebView2ExecuteScriptCompletedHandlerCreate($bPrint = False)
    $pCoreWebView2ExecuteScriptCompletedHandler = ObjectFromTag("CoreWebView2ExecuteScriptCompletedHandler_", _
            $dtag_ICoreWebView2ExecuteScriptCompletedHandler, _
            $tCoreWebView2ExecuteScriptCompletedHandler, _
            False, _
            $bPrint)
    If $bPrint Then ConsoleWrite("$pCoreWebView2ExecuteScriptCompletedHandler = " & $pCoreWebView2ExecuteScriptCompletedHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandlerCreate

Func CoreWebView2ExecuteScriptCompletedHandlerDelete()
    $pCoreWebView2ExecuteScriptCompletedHandler = 0
    DeleteObjectFromTag($tCoreWebView2ExecuteScriptCompletedHandler)
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandlerDelete
; -------------------------------------------------------------------------------------------------------------------------
; Callback functions

Func CoreWebView2ExecuteScriptCompletedHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite("# invoked -> CoreWebView2ExecuteScriptCompletedHandler_QueryInterface() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandler_QueryInterface

Func CoreWebView2ExecuteScriptCompletedHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2ExecuteScriptCompletedHandler_AddRef() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandler_AddRef

Func CoreWebView2ExecuteScriptCompletedHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2ExecuteScriptCompletedHandler_Release() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandler_Release

; -------------------------------------------------------------------------------------------------------------------------
; == CapturePreview =======================================================================================================
Global $sIID_ICoreWebView2CapturePreviewCompletedHandler = "{697e05e9-3d8f-45fa-96f4-8ffe1ededaf5}"
Global $dtag_ICoreWebView2CapturePreviewCompletedHandler = _
        "Invoke hresult(LONG);" ; HRESULT error

Func CoreWebView2CapturePreviewCompletedHandlerCreate($bPrint = False)
    $pICoreWebView2CapturePreviewCompletedHandler = ObjectFromTag( _
            'CoreWebView2CapturePreviewCompletedHandler_', _
            $dtag_ICoreWebView2CapturePreviewCompletedHandler, _
            $tICoreWebView2CapturePreviewCompletedHandler, _
            False, _
            $bPrint)
    If $bPrint Then ConsoleWrite("$pICoreWebView2CapturePreviewCompletedHandler = " & $pICoreWebView2CapturePreviewCompletedHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandlerCreate

Func CoreWebView2CapturePreviewCompletedHandlerDelete()
    $pICoreWebView2CapturePreviewCompletedHandler = 0
    DeleteObjectFromTag($tICoreWebView2CapturePreviewCompletedHandler)
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandlerDelete

; -- Callback functions -----
Func CoreWebView2CapturePreviewCompletedHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite('***> CoreWebView2CapturePreviewCompletedHandler_QueryInterface' & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandler_QueryInterface

Func CoreWebView2CapturePreviewCompletedHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite('***> CoreWebView2CapturePreviewCompletedHandler_AddRef' & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandler_AddRef

Func CoreWebView2CapturePreviewCompletedHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite('***> CoreWebView2CapturePreviewCompletedHandler_Release' & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2CapturePreviewCompletedHandler_Release
; ======================================================================

; --- ICoreWebView2WebMessageReceivedEventHandler and related interfaces and functions ---

; ICoreWebView2WebMessageReceivedEventArgs interface
Global $oCoreWebView2WebMessageReceivedEventArgs
Global Const $sIID_ICoreWebView2WebMessageReceivedEventArgs = "{0F99A40C-E962-4207-9E92-E3D542EFF849}"
Global Const $dtag_ICoreWebView2WebMessageReceivedEventArgs = _
        "get_Source hresult(wstr*);" & _
        "get_WebMessageAsJson hresult(wstr*);" & _
        "TryGetWebMessageAsString hresult(wstr*);"

; ICoreWebView2WebMessageReceivedEventHandler callback interface

Global Const $sIID_ICoreWebView2WebMessageReceivedEventHandler = "{57213F19-00E6-49FA-8E07-898EA01ECBD2}"
Global Const $dtag_ICoreWebView2WebMessageReceivedEventHandler = _
        "Invoke hresult(ptr*;ptr*);"

; Functions to create and delete the callback interface

; Functions to create and delete the callback interface
#cs
Func CoreWebView2ExecuteScriptCompletedHandlerCreate($bPrint = False)
    $pCoreWebView2ExecuteScriptCompletedHandler = ObjectFromTag("CoreWebView2ExecuteScriptCompletedHandler_", _
            $dtag_ICoreWebView2ExecuteScriptCompletedHandler, _
            $tCoreWebView2ExecuteScriptCompletedHandler, _
            False, _
            $bPrint)
    If $bPrint Then ConsoleWrite("$pCoreWebView2ExecuteScriptCompletedHandler = " & $pCoreWebView2ExecuteScriptCompletedHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2ExecuteScriptCompletedHandlerCreate
#ce
Func CoreWebView2WebMessageReceivedEventHandlerCreate($bPrint = False)
    $pCoreWebView2WebMessageReceivedEventHandler = ObjectFromTag("CoreWebView2WebMessageReceivedEventHandler_", _
            $dtag_ICoreWebView2WebMessageReceivedEventHandler, _
            $tCoreWebView2WebMessageReceivedEventHandler, _
            False, _
            $bPrint)
    If $bPrint Then ConsoleWrite("$pCoreWebView2WebMessageReceivedEventHandler = " & $pCoreWebView2WebMessageReceivedEventHandler & @CRLF & @CRLF)
EndFunc   ;==>CoreWebView2WebMessageReceivedEventHandlerCreate

Func CoreWebView2WebMessageReceivedEventHandlerDelete()
    $pCoreWebView2WebMessageReceivedEventHandler = 0
    DeleteObjectFromTag($tCoreWebView2WebMessageReceivedEventHandler)
EndFunc   ;==>CoreWebView2WebMessageReceivedEventHandlerDelete

; Callback functions

Func CoreWebView2WebMessageReceivedEventHandler_QueryInterface($pSelf, $pRIID, $pObj)   ; Ret: long  Par: ptr;ptr*
    ConsoleWrite("# invoked -> CoreWebView2WebMessageReceivedEventHandler_QueryInterface() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $pRIID, $pObj
EndFunc   ;==>CoreWebView2WebMessageReceivedEventHandler_QueryInterface

Func CoreWebView2WebMessageReceivedEventHandler_AddRef($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2WebMessageReceivedEventHandler_AddRef() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2WebMessageReceivedEventHandler_AddRef

Func CoreWebView2WebMessageReceivedEventHandler_Release($pSelf)   ; Ret: dword
    ConsoleWrite("# invoked -> CoreWebView2WebMessageReceivedEventHandler_Release() (Script: WV2Interfaces.au3 Line: " & @ScriptLineNumber & @CRLF)
    Return 1 ; For AddRef/Release
    #forceref $pSelf
EndFunc   ;==>CoreWebView2WebMessageReceivedEventHandler_Release

#cs
Function copied to example code
Func CoreWebView2WebMessageReceivedEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long  Par: ptr*;ptr*
    ConsoleWrite( "CoreWebView2WebMessageReceivedEventHandler_Invoke()" & @CRLF & @CRLF )
    Return 0 ; S_OK = 0x00000000
    #forceref $pSelf, $ptr1, $ptr2
EndFunc
#ce

 

Edited by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

@Gianni Grazie mille. I will have a deeper look tomorrow.

 

Btw, here the SHCreateStreamOnFileEx function:

;Coded by UEZ build 2023-08-28
#include <WinAPIFiles.au3>

Const   $STGM_FAILIFTHERE = 0, $STGM_DIRECT = 0, $STGM_READ = 0, $STGM_WRITE = 1, $STGM_READWRITE = 2, _
        $STGM_SHARE_DENY_NONE = 0x00000040, $STGM_SHARE_DENY_READ = 0x00000030, $STGM_SHARE_DENY_WRITE = 0x00000020, $STGM_SHARE_EXCLUSIVE = 0x00000010, _
        $STGM_PRIORITY = 0x00040000, $STGM_CREATE = 0x00001000, $STGM_CONVERT = 0x00020000, _
        $STGM_TRANSACTED = 0x00010000, $STGM_NOSCRATCH = 0x00100000, $STGM_NOSNAPSHOT = 0x00200000, $STGM_SIMPLE = 0x08000000, $STGM_DIRECT_SWMR = 0x00400000, $STGM_DELETEONRELEASE = 0x04000000
        

;https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-shcreatestreamonfileex
Func _WinAPI_SHCreateStreamOnFileEx($sFile, $grfMode, $dwAttributes, $fCreate)
    Local $iLen = StringLen($sFile)
    If Not $iLen Then Return SetError(1, 0, 0)
    Local $tFile = DllStructCreate("wchar szFile[" & $iLen & "]")
    $tFile.szFile = $sFile
    Local $aResult = DllCall("Shlwapi.dll", "long", "SHCreateStreamOnFileEx", "struct*", $tFile, "dword", $grfMode, "dword", $dwAttributes, "bool", $fCreate, "ptr", Null, "ptr*", 0)
    If $aResult[0] Or @error Then Return SetError(2, $aResult[0], 0)
    Return $aResult[6]
EndFunc

Global $hStream = _WinAPI_SHCreateStreamOnFileEx('c:\temp\SShot.jpg', BitOR($STGM_READWRITE, $STGM_CREATE), $FILE_ATTRIBUTE_NORMAL, True)

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...