Page 1 of 2 12 LastLast
Results 1 to 40 of 45

Thread: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    download webview sdk *.nupkg
    you can find:
    webview.tlb , WebView2.idl WebView2Loader.dll

    https://globalcdn.nuget.org/packages....1774.30.nupkg
    https://learn.microsoft.com/en-us/mi...s=dotnetcsharp
    rename as zip file,unzip

    ---------------
    This is just a simple example to open a URL. More can be done with TLB files or better dynamic lightweight COM interfaces.

    Code:
        If CreateCoreWebView2EnvironmentWithOptions(strptr(""), strptr(""), 0&, ObjPtr(WebCompletedHandler)) <> S_OK Then
            MessageBox 0, "Failed to create environment", "Error", 0
            Else
            Form1.Caption = "New Webview OK"
        End If
    Last edited by xiaoyao; Oct 30th, 2023 at 11:01 AM. Reason: change title

  2. #2
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview demo by IUnknown,without rc6.dll

    Very good work.
    Is it possible to add extensions?
    thanks

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    Very good work.
    Is it possible to add extensions?
    thanks
    do you test it?run ok by Compile an EXE file?
    waht about run on vb6 ide?
    you can add code like this sample,add more method like runjs,get js value ,eval(**)

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview demo by IUnknown,without rc6.dll

    the second callback IS AClass_OpenUrl.bas show err in vb6 ide:
    Private Function Invoke(This As DemonBlog, ByVal Errcode As Long, ByVal OBJ1Address As Long) As Long
    Errcode<>0

    Errcode=-2147024726, ERRINFO:The requested resource is in use


    Code:
    Private Declare Function FormatMessage Lib "kernel32.dll" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
    Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
    Private Const FORMAT_MESSAGE_IGNORE_InsertS = &H200
    Declare Function GetLastError Lib "kernel32" () As Long
    
    Public Function GetLastDllErr(ByVal lErr As Long) As String
    Dim sReturn As String
    sReturn = String$(256, 32)
    FormatMessage FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_InsertS, 0&, lErr, 0&, sReturn, Len(sReturn), ByVal 0
    sReturn = Trim(sReturn)
    GetLastDllErr = sReturn
    End Function
    Last edited by xiaoyao; Jun 2nd, 2023 at 08:27 PM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview demo by IUnknown,without rc6.dll

    create webview2 object by vb6,CreateCoreWebView2EnvironmentWithOptions-VBForums
    https://www.vbforums.com/showthread....entWithOptions

  6. #6
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    works fine, only out of 10 times 2 closed when CreateWebView was called.
    One question, how do you look for the functions and the index?
    Code:
    r = DispCallByVtbl(webviewWindow, 3 + 2, StrPtr(Url))

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    works fine, only out of 10 times 2 closed when CreateWebView was called.
    One question, how do you look for the functions and the index?
    Code:
    r = DispCallByVtbl(webviewWindow, 3 + 2, StrPtr(Url))
    ii fix it,now it's all right.you can download new version t try.

    com VTable like this,first is (QueryInterface+AddRef+Invoke)
    so Invoke VTable(3) address if 3*4=12
    here we use 3,DispCallByVtbl will put index=3*4

    Code:
     
               .VTable(0) = GetAddress(AddressOf QueryInterface)
                .VTable(1) = GetAddress(AddressOf AddRef)
                .VTable(2) = GetAddress(AddressOf Release)
                .VTable(3) = GetAddress(AddressOf Invoke)
    Navigate is the 3rd method, plus IUnknown has 3 methods by default,
    which is actually 3+3-1
    This is the offset, and the first QueryInterface must be 0.
    So the 6th is actually offset = 5*4

    Code:
    webview2.h:
        ICoreWebView2 : public IUnknown
        {
        public:
            virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Settings( 
                /* [retval][out] */ ICoreWebView2Settings **settings) = 0;
            
            virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Source( 
                /* [retval][out] */ LPWSTR *uri) = 0;
            
            virtual HRESULT STDMETHODCALLTYPE Navigate(
    More of the following operations are for this ICoreWebView2 object:
    AddScriptToExecuteOnDocumentCreated
    ExecuteScript
    CallDevToolsProtocolMethod
    GoBack,GoForward
    Stop
    get_DocumentTitle
    AddHostObjectToScript (like put form1 to js)
    OpenDevToolsWindow
    Last edited by xiaoyao; Jun 3rd, 2023 at 05:00 AM.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    you can download a vc++ demo for study how to do this.
    and add more method to vb6 webview object
    like runjs,eval(js)
    vc++ com not same like vb6,It was very difficult, and it took more than a year to finally solve this problem.
    THE MAIN THING IS THAT I ASKED CHATGPT THE OTHER DAY, THE GUY GAVE A PIECE OF CODE NONSENSE, AND IT TURNED OUT TO BE COMPLETELY UNRUNTABLE.

    LATER, BASED ON THIS PRINCIPLE, USE MODULE1.BAS TO SIMULATE AN IUnknown object out, and it keeps crashing, at the beginning it requires 3 PARAMETERS, I ONLY USED 2, THE THIRD PARAMETER BEHIND USED THE OBJECT OBJECT, AND CRASHED AGAIN, USING THE POINTER LONG VARIABLE, AND THEN TAKING OUT THE OBJECT INSTANCE FROM THE POINTER.
    Code:
    Private Function Invoke(This As DemonBlog, ByVal errorCode As Long, ByVal OBJ1Address As Long) As Long

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    vc++ for show a webview2 window,it's easy,but i change to vb6,used some months

    Code:
    	HRESULT res = CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
    		Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
    			[hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
    		// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWnd
    		env->CreateCoreWebView2Controller(hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
    			[hWnd](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
    			if (controller != nullptr) {
    				webviewController = controller;
    				webviewController->get_CoreWebView2(&webviewWindow);
    			}
    
    			// Resize WebView to fit the bounds of the parent window
    			RECT bounds;
    			GetClientRect(hWnd, &bounds);
    			webviewController->put_Bounds(bounds);
    
    
    			HRESULT res = webviewWindow->Navigate(L"https:\\www.baidu.com");
    
    			return S_OK;
    		}).Get());
    		return S_OK;
    	}).Get());

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    now it's good for show webview
    CreateCoreWebView2EnvironmentWithOptions(StrPtr(edgesdk), StrPtr(userdata)

    this code run on vb6 ide will cash,why?
    CreateCoreWebView2EnvironmentWithOptions(0&, 0&

    and i put some code for free some object,so run in vb6 ide,No problem at all.
    If you're a good programmer, you can make this code simpler and more efficient.

    RemoveClass3
    RemoveClass1
    Set WebCompletedHandler = Nothing
    Last edited by xiaoyao; Jun 3rd, 2023 at 05:02 AM.

  11. #11
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    The new version works fine.
    To play with her.

    this for insert text code to the page.
    Code:
    Function NavigateToString(htmlContent As String)
        Dim r As Long
        r = DispCallByVtbl(webviewWindow, 3 + 3, StrPtr(htmlContent))
    End Function
    but i don't know how to do this
    Code:
            virtual HRESULT STDMETHODCALLTYPE ExecuteScript( 
                /* [in] */ LPCWSTR javaScript,
                /* [in] */ IWebView2ExecuteScriptCompletedHandler *handler) = 0;

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    add some webviewe method

    Code:
    Function OpenUrl(ByVal Url As String)
        If Left(LCase(Url), 4) <> "http" Then Url = "http://" & Url
        v = VTableCallEx("Navigate", webviewWindow, 3, StrPtr(Url))
    End Function
    
    Function OpenDevToolsWindow()
        v = VTableCallEx("OpenDevToolsWindow", webviewWindow, 49)
    End Function
    
    Function ExecuteScript(JS As String)
      v = VTableCallEx("ExecuteScript", webviewWindow, 27, StrPtr(JS), 0&)
    End Function
    
    Function AddHostObjectToScript(ObjName As String, Obj1 As Object)
      v = VTableCallEx("AddHostObjectToScript", webviewWindow, 47, StrPtr(ObjName), ObjPtr(Obj1))
      AddHostObjectToScript = hResult = 0
    End Function
    
    Function WebReSize() As Boolean
        Dim RECT1 As RECT
        GetClientRect webHostHwnd, RECT1
        'webviewController->put_Bounds(bounds);
        v = VTableCallEx("put_Bounds", webviewController, 4, RECT1.Left, RECT1.Top, RECT1.Right, RECT1.Bottom)
        WebReSize = hResult = 0
    End Function
    Last edited by xiaoyao; Oct 30th, 2023 at 11:02 AM.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    The new version works fine.
    To play with her.

    this for insert text code to the page.
    Code:
    Function NavigateToString(htmlContent As String)
        Dim r As Long
        r = DispCallByVtbl(webviewWindow, 3 + 3, StrPtr(htmlContent))
    End Function
    but i don't know how to do this
    Code:
            virtual HRESULT STDMETHODCALLTYPE ExecuteScript( 
                /* [in] */ LPCWSTR javaScript,
                /* [in] */ IWebView2ExecuteScriptCompletedHandler *handler) = 0;
    IWebView2ExecuteScriptCompletedHandler *handler
    you need make class3/CLASSC in module,
    LIKE THIS
    Code:
    Public Function InitializeDemonBlog(LE As DemonBlog) As IUnknown 'IDemonBlog
        If m_pVTable = 0 Then
            With m_VTable
                .VTable(0) = GetAddress(AddressOf QueryInterface)
                .VTable(1) = GetAddress(AddressOf AddRef)
                .VTable(2) = GetAddress(AddressOf Release)
                .VTable(3) = GetAddress(AddressOf Invoke)
               *******
                m_pVTable = VarPtr(.VTable(0))

  14. #14
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Very good work.
    You've made a lot of progress.
    It's hard for me to understand some functions because I'm new to vtable.
    For example.
    How to get the return value
    Code:
    Function get_Source() As Variant
        If Left(LCase(Url), 4) <> "http" Then Url = "http://" & Url
        v = VTableCallEx("get_Source", webviewWindow, 2)
        get_Source = v
    End Function

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    Very good work.
    You've made a lot of progress.
    It's hard for me to understand some functions because I'm new to vtable.
    For example.
    How to get the return value
    Code:
    virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Source( 
                /* [retval][out] */ LPWSTR *uri) = 0;
    out ,so you only put string or byte array here ,put strptr or varptr(buffer(0))

    all this com object method,result is SOK=0
    SO IF YOU WANT TO GET string or get object,Just pass the variable to return the data to the parameter

    for example:get webview object
    Code:
    'For :webviewController->get_CoreWebView2(&webviewWindow);
    r = DispCallByVtbl(webviewController, 23 + 2, VarPtr(webviewWindowPtr))
     Set webviewWindow = ObjFromPtr(VarPtr(webviewWindowPtr))
    Code:
    Function get_Source() As String
        Dim S As String, ID As Long
        S = String(500, " ")
        v = VTableCallEx("get_Source", webviewWindow, 2, VarPtr(S))
        If hResult <> 0 Then Exit Function
        ID = InStr(S, Chr(0))
        If ID > 0 Then S = Left(S, ID - 1)
        get_Source = S
    End Function
    Last edited by xiaoyao; Jun 3rd, 2023 at 09:48 AM.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Code:
    Private Sub DoAddHostObjectToScript_Click()
    MsgBox AddHostObjectToScript("Form1", Me)
    End Sub
    Private Sub doObjectTest_Click()
    
     ExecuteScript "const ObjForm1=window.chrome.webview.hostObjects.Form1;alert(ObjForm1.GetCaption)"
    how to call host exe object by js?

  17. #17
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by xiaoyao View Post
    Code:
    virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Source( 
                /* [retval][out] */ LPWSTR *uri) = 0;
    out ,so you only put string or byte array here ,put strptr or varptr(buffer(0))

    all this com object method,result is SOK=0
    SO IF YOU WANT TO GET string or get object,Just pass the variable to return the data to the parameter

    for example:get webview object
    Code:
    'For :webviewController->get_CoreWebView2(&webviewWindow);
    r = DispCallByVtbl(webviewController, 23 + 2, VarPtr(webviewWindowPtr))
     Set webviewWindow = ObjFromPtr(VarPtr(webviewWindowPtr))
    Code:
    Function get_Source() As String
        Dim S As String, ID As Long
        S = String(500, " ")
        v = VTableCallEx("get_Source", webviewWindow, 2, VarPtr(S))
        If hResult <> 0 Then Exit Function
        ID = InStr(S, Chr(0))
        If ID > 0 Then S = Left(S, ID - 1)
        get_Source = S
    End Function
    thanks works perfect

    Quote Originally Posted by xiaoyao View Post
    Code:
    Private Sub DoAddHostObjectToScript_Click()
    MsgBox AddHostObjectToScript("Form1", Me)
    End Sub
    Private Sub doObjectTest_Click()
    
     ExecuteScript "const ObjForm1=window.chrome.webview.hostObjects.Form1;alert(ObjForm1.GetCaption)"
    how to call host exe object by js?
    it doesn't work
    AddHostObjectToScript return True but Alert return "function() { [native code] }"

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    AddHostObjectToScript
    maybe also need put a new class like classA(MODULE BAS)

    The following code defines the IHostObjectSample interface, which inherits the IUnknownCOM standard. Use this IHostObjectSample definition as a template for defining object methods, properties, callback functions, and so on.

    Call native-side code from web-side code - Microsoft Edge Development | Microsoft Learn
    https://learn.microsoft.com/en-us/mi...ect?tabs=win32

    Code:
    import "oaidl.idl";
    import "ocidl.idl";
    
    [uuid(0a7a4655-5660-47d0-8a37-98ae21399e57), version(0.1)]
    library HostObjectSampleLibrary
    {
        [uuid(3a14c9c0-bc3e-453f-a314-4ce4a0ec81d8), object, local]
        interface IHostObjectSample : IUnknown
        {
            // Demonstrates a basic method call with some parameters and a return value.
            HRESULT MethodWithParametersAndReturnValue([in] BSTR stringParameter, [in] INT integerParameter, [out, retval] BSTR* stringResult);
    
            // Demonstrate getting and setting a property.
            [propget] HRESULT Property([out, retval] BSTR* stringResult);
            [propput] HRESULT Property([in] BSTR stringValue);
    
            [propget] HRESULT IndexedProperty(INT index, [out, retval] BSTR * stringResult);
            [propput] HRESULT IndexedProperty(INT index, [in] BSTR stringValue);
    
            // Demonstrate native calling back into JavaScript.
            HRESULT CallCallbackAsynchronously([in] IDispatch* callbackParameter);
    
            // Demonstrates a property which uses Date types.
            [propget] HRESULT DateProperty([out, retval] DATE * dateResult);
            [propput] HRESULT DateProperty([in] DATE dateValue);
    
            // Creates a date object on the native side and sets the DateProperty to it.
            HRESULT CreateNativeDate();
    
        };

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    need oleexp.tlb (ver 6.2)

    HostObjectClass.cls
    Code:
    Public Sub Test()
        MsgBox "Call EXE Class Test from JS"
    End Sub
    Code:
    public   HostObj As New HostObjectClass
    AddHostObjectToScript_OleExp("HostClass", HostObj)
    
    Function AddHostObjectToScript_OleExp(ByVal ObjName As String, Obj1 As Object)
    Dim w As ICoreWebView2
    Dim NN As IUnknown
    Set NN = webviewWindow
    Set w = NN
    w.AddHostObjectToScript StrPtr(ObjName), Obj1
    End Function
    
    
    Private Sub doObjectTest_Click()
    Static intHostClassAOK As Boolean
    If Not intHostClassAOK Then
        intHostClassAOK = True
        ExecuteScript "const HostClassA=window.chrome.webview.hostObjects.HostClass;"
     End If
      ExecuteScript "HostClassA.Test();"
    end sub
    Last edited by xiaoyao; Jun 3rd, 2023 at 10:32 AM.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    now it's ok, Obj1 As Variant need change to this type

    Code:
    Function AddHostObjectToScript(ObjName As String, Obj1 As Variant)
      v = VTableCallEx("AddHostObjectToScript", webviewWindow, 47, StrPtr(ObjName), VarPtr(Obj1))
      AddHostObjectToScript = hResult = 0
    End Function
    New version use:
    Code:
    v = CallWebView("AddHostObjectToScript", StrPtr(ObjName), VarPtr(Obj1))
    Code:
    virtual HRESULT STDMETHODCALLTYPE AddHostObjectToScript( 
                /* [in] */ LPCWSTR name,
                /* [in] */ VARIANT *object) = 0;
    new version demo5 at first on top
    Last edited by xiaoyao; Jun 3rd, 2023 at 11:02 AM.

  21. #21
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    In console dev error
    Code:
    Uncaught (in promise) {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 1}callId: 1methodName: ""parameters: {error: 'No se ha encontrado el elemento. (0x80070490)', kind: 'response'}error: "No se ha encontrado el elemento. (0x80070490)"kind: "response"[[Prototype]]: ObjectremoteObjectId: 0[[Prototype]]: Object

  22. #22
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    The new version works very well.
    Why don't you use Enum instead of MethodID_ICoreWebView2.txt
    Example
    Code:
    Public Enum MethodName
        MN_get_Settings = 1
        MN_get_Source = 2
        MN_Navigate = 3
        MN_NavigateToString = 4
        MN_add_NavigationStarting = 5
        .....
    End Enum

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    The new version works very well.
    Why don't you use Enum instead of MethodID_ICoreWebView2.txt
    Enum or by keylist,Either way is fine. My favorite is to simply query the virtual table name, get all the interface function names, and store them in the array.

    Microsoft code is always smelly and long,makey more hours,now it's successfull
    HostObjectClass.cls
    Code:
    Dim Itemv As String
    
    Private Sub Class_Initialize()
    Itemv = "Now:" & Now
    End Sub
    
    Public Function ClassAdd(a, b) As Long
        ClassAdd = a + b
    End Function
    
    Public Property Get Item() As String
        Item = Itemv
    End Property
    
    Public Property Let Item(ByVal vNewValue As String)
        Itemv = vNewValue
    End Property
    Code:
        MsgBox AddHostObjectToScript_NEW("HostClass", HostObj)
        ExecuteScript "const HostClassA2=window.chrome.webview.hostObjects.sync.HostClass;"
        ExecuteScript "alert(HostClassA2.ClassAdd(33,44));"
    Code:
    Private Sub doObjectTest_Click()
    
      ExecuteScript "alert(HostClassA2.Item)"
      ExecuteScript "HostClassA2.Item='new str';alert(HostClassA2.Item);"
    End Sub
    Last edited by xiaoyao; Jun 3rd, 2023 at 12:09 PM.

  24. #24
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Code:
    Set WebviewMethodDc = CallWebview2.MethodDictionary
    Set WebviewMethodDc = MethodDictionary
    
    Public Function MethodDictionary() As Dictionary
        Set MethodDictionary = New Dictionary
        MethodDictionary.CompareMode = TextCompare
        MethodDictionary.Add "get_Settings", 1
        MethodDictionary.Add "get_Source", 2
        MethodDictionary.Add "Navigate", 3
        MethodDictionary.Add "NavigateToString", 4
        MethodDictionary.Add "add_NavigationStarting", 5
        MethodDictionary.Add "remove_NavigationStarting", 6
        MethodDictionary.Add "add_ContentLoading", 7
        MethodDictionary.Add "remove_ContentLoading", 8
        MethodDictionary.Add "add_SourceChanged", 9
        MethodDictionary.Add "remove_SourceChanged", 10
        MethodDictionary.Add "add_HistoryChanged", 11
        MethodDictionary.Add "remove_HistoryChanged", 12
        MethodDictionary.Add "add_NavigationCompleted", 13
        MethodDictionary.Add "remove_NavigationCompleted", 14
        MethodDictionary.Add "add_FrameNavigationStarting", 15
        MethodDictionary.Add "remove_FrameNavigationStarting", 16
        MethodDictionary.Add "add_FrameNavigationCompleted", 17
        MethodDictionary.Add "remove_FrameNavigationCompleted", 18
        MethodDictionary.Add "add_ScriptDialogOpening", 19
        MethodDictionary.Add "remove_ScriptDialogOpening", 20
        MethodDictionary.Add "add_PermissionRequested", 21
        MethodDictionary.Add "remove_PermissionRequested", 22
        MethodDictionary.Add "add_ProcessFailed", 23
        MethodDictionary.Add "remove_ProcessFailed", 24
        MethodDictionary.Add "AddScriptToExecuteOnDocumentCreated", 25
        MethodDictionary.Add "RemoveScriptToExecuteOnDocumentCreated", 26
        MethodDictionary.Add "ExecuteScript", 27
        MethodDictionary.Add "CapturePreview", 28
        MethodDictionary.Add "Reload", 29
        MethodDictionary.Add "PostWebMessageAsJson", 30
        MethodDictionary.Add "PostWebMessageAsString", 31
        MethodDictionary.Add "add_WebMessageReceived", 32
        MethodDictionary.Add "remove_WebMessageReceived", 33
        MethodDictionary.Add "CallDevToolsProtocolMethod", 34
        MethodDictionary.Add "get_BrowserProcessId", 35
        MethodDictionary.Add "get_CanGoBack", 36
        MethodDictionary.Add "get_CanGoForward", 37
        MethodDictionary.Add "GoBack", 38
        MethodDictionary.Add "GoForward", 39
        MethodDictionary.Add "GetDevToolsProtocolEventReceiver", 40
        MethodDictionary.Add "Stop", 41
        MethodDictionary.Add "add_NewWindowRequested", 42
        MethodDictionary.Add "remove_NewWindowRequested", 43
        MethodDictionary.Add "add_DocumentTitleChanged", 44
        MethodDictionary.Add "remove_DocumentTitleChanged", 45
        MethodDictionary.Add "get_DocumentTitle", 46
        MethodDictionary.Add "AddHostObjectToScript", 47
        MethodDictionary.Add "RemoveHostObjectFromScript", 48
        MethodDictionary.Add "OpenDevToolsWindow", 49
        MethodDictionary.Add "add_ContainsFullScreenElementChanged", 50
        MethodDictionary.Add "remove_ContainsFullScreenElementChanged", 51
        MethodDictionary.Add "get_ContainsFullScreenElement", 52
        MethodDictionary.Add "add_WebResourceRequested", 53
        MethodDictionary.Add "remove_WebResourceRequested", 54
        MethodDictionary.Add "AddWebResourceRequestedFilter", 55
        MethodDictionary.Add "RemoveWebResourceRequestedFilter", 56
        MethodDictionary.Add "add_WindowCloseRequested", 57
        MethodDictionary.Add "remove_WindowCloseRequested", 58
    End Function

  25. #25
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    You could move everything to a class.
    To be able to have many instances of the browser

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    HostObjectClass.cls , for eval js,get js result

    a=Eval("document.title")
    a=eval("33+44")

    Code:
    Public JsResult As String
    Function Eval(js As String) As String
        JsResult = ""
        Dim Start As Long:Start = timeGetTime
        ExecuteScript "HostClassA2.ReturnVal(" & js & ")"
        
        While JsResult = "" And timeGetTime - Start < 1000
        DoEvents:    Wend
        Eval = JsResult
    End Function
    
    Public Sub ReturnVal(s)
        JsResult = s
    End Sub
    Last edited by xiaoyao; Jun 3rd, 2023 at 12:56 PM.

  27. #27

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by yokesee View Post
    The new version works fine.
    To play with her.
    this for insert text code to the page.
    Function NavigateToString(htmlContent As String)
    vb6_webview2_Demo6.zip

    Code:
    Private Sub btNavigateToString_Click()
        NavigateToString "<html><head><meta http-equiv=""Content-Type"" content=""text/html;charset=utf-8"">" _
        & "<body><font color='red'>vb6 webview demo<a href='https://www.vbforums.com/showthread.php?900231'>&nbsp;&nbsp; DownLoad Test</a></font></body>"
    End Sub
    
    Function NavigateToString(Htm As String) As Boolean
      v = CallWebView("NavigateToString", StrPtr(Htm))
    End Function
    study webview2 how to use: Using the new Chromium WebView2 control in .NET - Part 1 - Rick Strahl's Weblogs
    https://weblog.west-wind.com/posts/2...-in-NET-Part-1
    Last edited by xiaoyao; Jun 3rd, 2023 at 01:25 PM.

  28. #28

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2(Edge-Chromium) by IUnknown WebView2Loader.dll

    ExcuteScript eval(document.body.innerHTML):
    from :https://www.163.com
    The resulting string takes up 1.2MB of byte space

    Get the JS execution result in the ExcuteScript callback event, it takes 54 milliseconds
    Among them, JSON to character 13.5209 milliseconds
    jSON data length: increased by 19.2%
    ---------------------------
    It takes about 23 milliseconds for JS to call the method in the host object to return the result
    UsedTime=23.157 MS WaitTime: 23.1085 Ms
    For results such as Doevents infinite loop, increase the time by 2-3 milliseconds.
    But the process of waiting will occupy other core CPU
    ---------------------------
    [Active] If you look at the eyes, enter the eyes three points said:
    I don't know what your speed measurement means?

    i say: This speed measurement is of course important. Writing this thing is not mainly for viewing web pages.
    For example, automatic login, automatic click, extracting webpage content, and a large number of JS operations
    Maybe the fastest way is to insert all the code into JS to execute on the page, just return the progress
    Send data back regularly when needed. There is no need to execute JS tens of thousands of times at high frequency

    Another way is to send and receive data through the websocket protocol
    Last edited by xiaoyao; Jun 3rd, 2023 at 09:34 PM.

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Invalid: Dim WithEvents WebView2 As WebView2.ICoreWebView2 'object is not the source automatic event
    ---------------------------
    Call WebView.add_FrameNavigationCompleted(0, 0)
    Compilation error: The variable uses an automated type that Visual Basic does not support

  30. #30
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    How to use WebView2 in Chromium.
    You have an example.

    It can be used in more windows.

    All the best

  31. #31

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Quote Originally Posted by yokesee View Post
    How to use WebView2 in Chromium.
    You have an example.

    It can be used in more windows.

    All the best
    I hope you to test more. Have you encountered any problems?
    I always thought it was a bad decision for Microsoft not to give us VB6 to use webview 2.

    ii ask in edge github,It took about two years for someone to reply and tell me that they had no plans for this improvement.
    In fact, they should have completed this requirement five or ten years ago.

    let vbs,vba can load webview,Use it without any difficulty.
    Microsoft doesn't want to do these things at all. It doesn't value the old users.
    He gave up the VBA and the old users.

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Quote Originally Posted by yokesee View Post
    How to use WebView2 in Chromium.
    You have an example.

    It can be used in more windows.

    All the best
    You can test more and reply in time if you have any questions.

    I don't understand what you said?
    Maybe modify this code to run on Excel VBA 64 bit.
    Last edited by xiaoyao; Jun 6th, 2023 at 01:38 PM.

  33. #33
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Quote Originally Posted by xiaoyao View Post
    You can test more and reply in time if you have any questions.
    I don't understand what you said?
    use webview2 in 2,3,4...Picturebox,
    or have two forms open with webview2 in Picturebox.


    your example only works for a single Picturebox

  34. #34

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Quote Originally Posted by yokesee View Post
    use webview2 in 2,3,4...Picturebox,
    or have two forms open with webview2 in Picturebox.


    your example only works for a single Picturebox
    If you want to display two web page controls《webview2 object》 in one program.
    Of course, this can be achieved, and you need some technology to improve it.

  35. #35
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    481

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Yes that.

    Thank you very much for all your work

  36. #36

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    event-driven programming is much more difficult than previous webbrowser operations. this is the order in which vb6 webview2 is loaded, and it can't be wrong.

    1,CreateCoreWebView2EnvironmentWithOptions(with call back ***)
    2,call back events:ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler
    for CreateCoreWebView2Controller(Callback**)
    3,call back events:ICoreWebView2CreateCoreWebView2ControllerCompletedHandler
    get object:webviewController
    get object:webviewWindow vc++ webviewController->get_CoreWebView2(&webviewWindow)
    Code:
    Set webviewWindow = ObjFromPtr(VarPtr(webviewWindowPtr))
     Set WebView = webviewWindow
    WebViewShowOK=true
    4, resize webview:webviewController->put_Bounds(bounds)
    5, Navigate Url ispCallByVtbl(webviewWindow, 3 + 2, StrPtr(Url))

    6,when Fom1 resize:
    resize webview:webviewController->put_Bounds(bounds)
    Code:
    Private Sub Form_Resize()
    If Me.WindowState <> 1 Then
        Picture1.Width = Me.ScaleWidth - Picture1.Left - 100
        Picture1.Height = Me.ScaleHeight - Picture1.Top - 100
        If WebViewShowOK Then WebReSize
    End If
    end sub
    Last edited by xiaoyao; Jun 8th, 2023 at 12:25 AM.

  37. #37
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    439

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    excellent, it seems that it has improved, I have not looked much in detail but the fact that it can run already makes me happy, there is something essential that I did not see, in RC6 there is a JSMessage event which
    Private sub WV_JSMessage(ByVal sMsg as String, ByVal sMsgContent as String, orJSONContent as cCollection)

    which can be called from javascript with something like vbH().RaiseMessageEvent('" & E & "','')"

    The MethodID_ICoreWebView2.txt thing is not necessary, because it does not declare an enumeration and calls each element, it is much better and more professional.

    Code:
    Public Enum vtb_Interfaces
        Get_Settings = 1
        Get_Source
        Navigate
        NavigateToString
        Add_NavigationStarting
        Remove_NavigationStarting
        Add_ContentLoading
        Remove_ContentLoading
        Add_SourceChanged
        Remove_SourceChanged
        Add_HistoryChanged
        Remove_HistoryChanged
        Add_NavigationCompleted
        Remove_NavigationCompleted
        Add_FrameNavigationStarting
        Remove_FrameNavigationStarting
        Add_FrameNavigationCompleted
        Remove_FrameNavigationCompleted
        Add_ScriptDialogOpening
        Remove_ScriptDialogOpening
        Add_PermissionRequested
        Remove_PermissionRequested
        Add_ProcessFailed
        Remove_ProcessFailed
        AddScriptToExecuteOnDocumentCreated
        RemoveScriptToExecuteOnDocumentCreated
        ExecuteScript
        CapturePreview
        Reload
        PostWebMessageAsJson
        PostWebMessageAsString
        Add_WebMessageReceived
        Remove_WebMessageReceived
        CallDevToolsProtocolMethod
        Get_BrowserProcessId
        Get_CanGoBack
        Get_CanGoForward
        GoBack
        GoForward
        GetDevToolsProtocolEventReceiver
        Stop_
        Add_NewWindowRequested
        Remove_NewWindowRequested
        Add_DocumentTitleChanged
        Remove_DocumentTitleChanged
        Get_DocumentTitle
        AddHostObjectToScript
        RemoveHostObjectFromScript
        OpenDevToolsWindow
        Add_ContainsFullScreenElementChanged
        Remove_ContainsFullScreenElementChanged
        Get_ContainsFullScreenElement
        Add_WebResourceRequested
        Remove_WebResourceRequested
        AddWebResourceRequestedFilter
        RemoveWebResourceRequestedFilter
        Add_WindowCloseRequested
        Remove_WindowCloseRequested
    End Enum
    leandroascierto.com Visual Basic 6 projects

  38. #38

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 edge webview2 demo by IUnknown,without rc6.dll

    Quote Originally Posted by LeandroA View Post
    excellent, it seems that it has improved, I have not looked much in detail but the fact that it can run already makes me happy, there is something essential that I did not see, in RC6 there is a JSMessage event which
    It takes a lot of time to realize the main functions in WEBVIEW2, and it is quite difficult
    use enum,?
    ambiguous name found: Navigate
    Last edited by xiaoyao; Jun 8th, 2023 at 01:02 AM.

  39. #39
    New Member
    Join Date
    Jun 2023
    Posts
    5

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    win10 error:

  40. #40

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,340

    Re: vb6 webview2 by IUnknown WebView2Loader.dll-Edge-Chromium

    Quote Originally Posted by sqbcai View Post
    win10 error:
    do you run in vb6 ide?or exe file?
    need WebView2Loader.dll and install edge webview sdk

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width