With the .NET WebBrowser control we can do:
WebBrowser1.ObjectForScripting = new a_class();
where a_class
is declared as [ComVisible(True)]
.
After which the instance of a_class
is accessible to the javascript in the page under the name of window.external
.
How do I achieve the same with the VB6/VBA WebBrowser OCX control?
There is apparently no direct property to set.
There are WebBrowser1.Document.parentWindow
and WebBrowser1.Document.parentWindow.external
objects, both are not null
(provided the page has loaded), but assigning an instance of something to the latter results in
Runtime error 445
Object doesn't support this action.
Just to rule it out, I made the class I want to pass implement the IObjectSafety
interface, but that didn't do anything (the IObjectSafety
members are not even called).
I also tried inspecting the existing parentWindow.external
object with TypeLib Information. ClassClassInfoFromObject
fails with "Doesn't support automation or required interface," InterfaceInfoFromObject
fails with "Subscript out of range."