I have found Passing an array from Javascript to C++ solution, but I have another task: Passing an object from Javascript to C++ (if I use IWebBrowser2 with IDispatch)
I mean that I need call C++ method via window.external.method with JavaScript object argument
var obj = {name: "Petr", group: "Friend"};
window.external.myMethod(obj);
How to get access to object member “name”, “group”, etc. ?
You can access the object’s properties via the
IDispatchinterface and its methodsGetIDsOfNamesandInvoke.Depending on your definition of
myMethod, you should be receivingobjas either aVARIANTor anIDispatch *in your C++ code. If aVARIANT,vtshould beVT_DISPACTH, in which case you can safely dereferencepdispval.Once you have an
IDispatchpointer, you can useGetIDsOfNamesto get theDISPIDfor a property that you’re interested in like so:Once you have successfully received your
DISPID, you must callInvokedifferently according to whether you would like to get a value, set a value or call a method.For instance, to get a value:
See the documentation for
Invokefor more information about the different permutations when calling it.