WebView2 - IMA trying to change an option (ICoreWebView2xyz)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 318
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

WebView2 - IMA trying to change an option (ICoreWebView2xyz)

Post by Derren »

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.
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"
I'm sure there is some code missing, like loading the options or something similar to this line in the original post/code

Code: Select all

 If CoreWebView2\get_Settings(@Settings) <> #S_OK Or Settings = 0 : Goto Proc_Exit : EndIf


Here'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
User avatar
skywalk
Addict
Addict
Posts: 4241
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: WebView2 - IMA trying to change an option (ICoreWebView2xyz)

Post by skywalk »

Hi, this may be related to a bug I reported.
The code only fails with the DEBUGGER ON.

Code: Select all

Procedure IncrementCallback(JsonParameters$)
  Static Count
  Debug #PB_Compiler_Procedure +": " + JsonParameters$
  Count + 1
  ProcedureReturn UTF8(~"{ \"count\": "+Str(Count)+ "}")
EndProcedure

Procedure ComputeCallback(JsonParameters$)
  Debug #PB_Compiler_Procedure +": " + JsonParameters$
  Dim Parameters(0)
  ; Extract the parameters from the JSON
  ParseJSON(0, JsonParameters$)
  ExtractJSONArray(JSONValue(0), Parameters())
  Debug "Parameter 1: " + Parameters(0)
  Debug "Parameter 2: " + Parameters(1)
  ProcedureReturn UTF8(Str(Parameters(0) + Parameters(1)))
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu | #PB_Window_Invisible)
WebViewGadget(0, 0, 0, 400, 400)
SetGadgetText(0, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
BindWebViewCallback(0, "increment", @IncrementCallback())
BindWebViewCallback(0, "compute", @ComputeCallback())
; Show the window once the webview has been fully loaded
HideWindow(0, #False)
Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Derren
Enthusiast
Enthusiast
Posts: 318
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: WebView2 - IMA trying to change an option (ICoreWebView2xyz)

Post by Derren »

Dang, I think you're onto something.

It doesn't crash with the Debugger disabled and when I tried to use DisableDebugger and EnableDebugger, I got an IMA on the DisableDebugger line

Code: Select all

DisableDebugger ;IMA on this line
Options\put_AllowSingleSignOnUsingOSPrimaryAccount(#True) ;IMA "read error at address 0"
EnableDebugger
There was another reply but now it's gone. It mentioned that you can't change the options after the gadget was created.

Seems like a dead end, then :(
Post Reply