WebView2 - IMA trying to change an option (ICoreWebView2xyz)
Posted: Fri Sep 26, 2025 3:26 pm
Hi everybody,
I recently used the WebView Gadget quite a lot.
Apparently there's a lot to configure under the hood IF you know there is a hood.
I have no idea how people even know how to do that. I haven't found any hints in the documentation about "GetGadgetAttribute(WebView, #PB_WebView_ICoreController)"
I have some code that I basically copied from viewtopic.php?p=631898#p631898 and tried to modify and I'm stuck. I tend to stick to using functions that are documented in the help file.
I realise that copying the Microsoft doc makes no sense, but I'm really having trouble understanding what I need to do in this case.
I hope somebody can drop a helpful hint. That would be awesome. Thank you!
So here's the essential code. According to the microsoft doc ( ;https://learn.microsoft.com/en-us/micro ... rarguments) it should accept a bool, but I get an IMA.
I'm sure there is some code missing, like loading the options or something similar to this line in the original post/code
Here's the full code that runs when one removes the faulty, IMA-causing line
I recently used the WebView Gadget quite a lot.
Apparently there's a lot to configure under the hood IF you know there is a hood.
I have no idea how people even know how to do that. I haven't found any hints in the documentation about "GetGadgetAttribute(WebView, #PB_WebView_ICoreController)"
I have some code that I basically copied from viewtopic.php?p=631898#p631898 and tried to modify and I'm stuck. I tend to stick to using functions that are documented in the help file.
I realise that copying the Microsoft doc makes no sense, but I'm really having trouble understanding what I need to do in this case.
I hope somebody can drop a helpful hint. That would be awesome. Thank you!
So here's the essential code. According to the microsoft doc ( ;https://learn.microsoft.com/en-us/micro ... rarguments) it should accept a bool, but I get an IMA.
put_AllowSingleSignOnUsingOSPrimaryAccount
Sets the AllowSingleSignOnUsingOSPrimaryAccount property.
code: public HRESULT put_AllowSingleSignOnUsingOSPrimaryAccount(BOOL allow)
Code: Select all
Define Options.ICoreWebView2EnvironmentOptions
Options\put_AllowSingleSignOnUsingOSPrimaryAccount(#True) ;IMA "read error at address 0"Code: Select all
If CoreWebView2\get_Settings(@Settings) <> #S_OK Or Settings = 0 : Goto Proc_Exit : EndIfHere's the full code that runs when one removes the faulty, IMA-causing line
Code: Select all
;Code basically copied from User "breeze4me" - https://www.purebasic.fr/english/viewtopic.php?p=631898#p631898
Procedure myFunc(WebView)
Protected Result
Protected Controller.ICoreWebView2Controller
Protected CoreWebView2.ICoreWebView2
Protected Options.ICoreWebView2EnvironmentOptions
Options\put_AllowSingleSignOnUsingOSPrimaryAccount(#True) ;IMA "read error at address 0"
;https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environmentoptions?view=webview2-1.0.3405.78#put_additionalbrowserarguments
;put_AllowSingleSignOnUsingOSPrimaryAccount
;Sets the AllowSingleSignOnUsingOSPrimaryAccount property.
; public HRESULT put_AllowSingleSignOnUsingOSPrimaryAccount(BOOL allow)
If GadgetType(WebView) <> #PB_GadgetType_WebView : ProcedureReturn 0 : EndIf
Controller = GetGadgetAttribute(WebView, #PB_WebView_ICoreController)
If Controller = 0 : ProcedureReturn 0 : EndIf
If Controller\get_CoreWebView2(@CoreWebView2) <> #S_OK Or CoreWebView2 = 0 : ProcedureReturn 0 : EndIf
Proc_Exit:
If CoreWebView2 : CoreWebView2\Release() : EndIf
ProcedureReturn Result
EndProcedure
;----------------------------------------------------------------------------------------
OpenWindow(0, 0, 0, 1000, 900, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebViewGadget(2, 0, 35, 1000, 900)
SetGadgetText(2, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
Debug myFunc(2)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow