Using the .NET WebBrowser control, it is fairly simple to execute a member of an HtmlElement.
Assuming there is a JavaScript object called “player” with a member called “getLastSongPlayed”; calling this from the .NET WebBrowser control would go something like this:
HtmlElement elem = webBrowser1.Document.getElementById("player");
elem.InvokeMember("getLastSongPlayed");
Now my question is: How do I accomplish that using mshtml ?
Thanks in advance,
Aldin
EDIT:
I got it up and running, see my answer below !
FINALLY !! I got it up and running !
The reason for the
that was thrown, whenever I tried to reference the parentWindow of an mshtml.IHTMLDocument2 and / or assign it to an mshtml.IHTMLWindow2 window object had to do with Threading.
For some, unknown to me, reason it seems that the COM objects of mshtml.IHTMLWindow are operating on another Thread that must be of Single-Threaded Apartment (STA) state.
So the trick was, calling / executing the required piece of code on another Thread with STA state.
Here’s a sample code:
We’re now also able to reference the parentWindow of an mshtml.IHTMLDocument2 object and execute a sites script and / or our own (remember it must be on an STA thread):
This might save someone from headaches in the future. lol