Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set IHTMLEventObj2::fromElement

I'm trying to generate synthetic Javascript events in an Internet Explorer extension, and I'm having trouble getting the fromElement property to stick. Here's an excerpt of my code:

MsHtml.IHTMLDocument4 doc4 = ... // the document object
Object o = null;
MsHtml.IHTMLEventObj2 eObj = 
    (MsHtml.IHTMLEventObj2)doc4.CreateEventObject(ref o);

// string that specifies the from element, e.g. "document.getElementById('id1')":
string locator = ... 
object from = doc4.Script.GetType().InvokeMember("eval", 
                                                 BindingFlags.InvokeMethod, 
                                                 null, 
                                                 doc4.Script, 
                                                 new object[] { locator });

// from now holds a ref to an object that implements the IHTMLElement interface
eObj.fromElement = from;
IHTMLElement el = eObj.fromElement;
// el == null

What am I doing wrong here? eObj.fromElement should be equal to from, but it doesn't seem to be getting set.

like image 676
Greg Avatar asked Dec 04 '08 20:12

Greg


2 Answers

Just a wild shot in the dark but could it be because your passing a "null" object to the CreateEventObject method? What about if you change this:

Object o = null;

To this:

Object o = new Object();

On line 3 of your example?

like image 86
Luke Baughan Avatar answered Nov 11 '22 14:11

Luke Baughan


To find the right element you should try method getElementById from IHTMLDocument6: http://msdn.microsoft.com/en-us/library/cc288667

like image 1
outcoldman Avatar answered Nov 11 '22 14:11

outcoldman