Skip to content

Commit

Permalink
Fixed: Running WebBrowser with WebView2 in 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
XusinboyBekchanov committed Nov 21, 2023
1 parent 9515183 commit 67b85ee
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 120 deletions.
Binary file added lib/win32/WebView2Guid.lib
Binary file not shown.
Binary file modified lib/win32/WebView2Loader.dll.lib
Binary file not shown.
Binary file modified lib/win32/WebView2LoaderStatic.lib
Binary file not shown.
36 changes: 29 additions & 7 deletions mff/WebBrowser.bas
Expand Up @@ -247,7 +247,7 @@ Namespace My.Sys.Forms

#ifndef __USE_GTK__
#ifdef __USE_WEBVIEW2__
Function WebBrowser.EnvironmentHandlerAddRef stdcall (This_ As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As UInteger
Function WebBrowser.EnvironmentHandlerAddRef stdcall (This_ As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As culong
Dim As WebBrowser Ptr WebB = Handles.Get(This_)
If WebB Then
WebB->HandlerRefCount += 1
Expand All @@ -257,7 +257,7 @@ Namespace My.Sys.Forms
End If
End Function

Function WebBrowser.EnvironmentHandlerRelease stdcall (This_ As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As UInteger
Function WebBrowser.EnvironmentHandlerRelease stdcall (This_ As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As culong
Dim As WebBrowser Ptr WebB = Handles.Get(This_)
If WebB Then
WebB->HandlerRefCount -= 1
Expand Down Expand Up @@ -329,7 +329,7 @@ Namespace My.Sys.Forms
Return S_OK
End Function

Function WebBrowser.ControllerHandlerAddRef stdcall (This_ As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As UInteger
Function WebBrowser.ControllerHandlerAddRef stdcall (This_ As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As culong
Dim As WebBrowser Ptr WebB = Handles.Get(This_)
If WebB Then
WebB->HandlerRefCount += 1
Expand All @@ -339,7 +339,7 @@ Namespace My.Sys.Forms
End If
End Function

Function WebBrowser.ControllerHandlerRelease stdcall (This_ As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As UInteger
Function WebBrowser.ControllerHandlerRelease stdcall (This_ As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As culong
Dim As WebBrowser Ptr WebB = Handles.Get(This_)
If WebB Then
WebB->HandlerRefCount -= 1
Expand Down Expand Up @@ -391,9 +391,20 @@ Namespace My.Sys.Forms

Dim As Rect bounds
GetClientRect(WebB->FHandle, @bounds)
WebB->webviewController->lpVtbl->put_Bounds(WebB->webviewController, bounds)
#ifdef __FB_64BIT__
WebB->webviewController->lpVtbl->put_Bounds(WebB->webviewController, bounds)
#else
Dim Chrome_WidgetWin_0 As HWND = FindWindowEx(WebB->FHandle, 0, "Chrome_WidgetWin_0", 0)
Dim Chrome_WidgetWin_1 As HWND = FindWindowEx(Chrome_WidgetWin_0, 0, "Chrome_WidgetWin_1", 0)
Dim Chrome_RenderWidgetHostHWND As HWND = FindWindowEx(Chrome_WidgetWin_1, 0, "Chrome_RenderWidgetHostHWND", 0)
Dim IntermediateD3DWindow As HWND = FindWindowEx(Chrome_RenderWidgetHostHWND, 0, "Intermediate D3D Window", 0)
MoveWindow Chrome_WidgetWin_0, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow Chrome_WidgetWin_1, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow Chrome_RenderWidgetHostHWND, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow IntermediateD3DWindow, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
#endif

'WebB->webviewWindow->lpVtbl->Navigate(WebB->webviewWindow, "https://google.com/")
WebB->webviewWindow->lpVtbl->Navigate(WebB->webviewWindow, "https://google.com/")
End If
End If
Return S_OK
Expand Down Expand Up @@ -505,7 +516,18 @@ Namespace My.Sys.Forms
If (webviewController <> NULL) Then
Dim As Rect bounds
GetClientRect(FHandle, @bounds)
webviewController->lpVtbl->put_Bounds(webviewController, bounds)
#ifdef __FB_64BIT__
webviewController->lpVtbl->put_Bounds(webviewController, bounds)
#else
Dim Chrome_WidgetWin_0 As HWND = FindWindowEx(FHandle, 0, "Chrome_WidgetWin_0", 0)
Dim Chrome_WidgetWin_1 As HWND = FindWindowEx(Chrome_WidgetWin_0, 0, "Chrome_WidgetWin_1", 0)
Dim Chrome_RenderWidgetHostHWND As HWND = FindWindowEx(Chrome_WidgetWin_1, 0, "Chrome_RenderWidgetHostHWND", 0)
Dim IntermediateD3DWindow As HWND = FindWindowEx(Chrome_RenderWidgetHostHWND, 0, "Intermediate D3D Window", 0)
MoveWindow Chrome_WidgetWin_0, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow Chrome_WidgetWin_1, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow Chrome_RenderWidgetHostHWND, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
MoveWindow IntermediateD3DWindow, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom, True
#endif
End If
End Select
#endif
Expand Down
9 changes: 4 additions & 5 deletions mff/WebBrowser.bi
Expand Up @@ -32,17 +32,16 @@ Namespace My.Sys.Forms
#ifdef __USE_WEBVIEW2__
Dim As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr envHandler
Dim As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr completedHandler
Dim As HWND HWND = NULL
Dim As ICoreWebView2Controller Ptr webviewController = NULL
Dim As ICoreWebView2 Ptr webviewWindow = NULL
Dim As BOOL bEnvCreated = False
Dim As ULong HandlerRefCount = 0
Declare Static Function EnvironmentHandlerAddRef stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As UInteger
Declare Static Function EnvironmentHandlerRelease stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As UInteger
Declare Static Function EnvironmentHandlerAddRef stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As culong
Declare Static Function EnvironmentHandlerRelease stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr) As culong
Declare Static Function EnvironmentHandlerQueryInterface stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr, riid As REFIID, ppvObject As PVOID Ptr) As HRESULT
Declare Static Function EnvironmentHandlerInvoke stdcall (This As ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Ptr, errorCode As HRESULT, arg As ICoreWebView2Environment Ptr) As HRESULT
Declare Static Function ControllerHandlerAddRef stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As UInteger
Declare Static Function ControllerHandlerRelease stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As UInteger
Declare Static Function ControllerHandlerAddRef stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As culong
Declare Static Function ControllerHandlerRelease stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr) As culong
Declare Static Function ControllerHandlerQueryInterface stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr, riid As REFIID, ppvObject As PVOID Ptr) As HRESULT
Declare Static Function ControllerHandlerInvoke stdcall (This As ICoreWebView2CreateCoreWebView2ControllerCompletedHandler Ptr, result As HRESULT, createdController As ICoreWebView2Controller Ptr) As HRESULT
#else
Expand Down

0 comments on commit 67b85ee

Please sign in to comment.