views:

94

answers:

0

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 locator = ... // a string that specifies the from element, e.g. "document.getElementById('id1')"
object from = doc4.Script.GetType().InvokeMember("eval", BindingFlags.InvokeMethod, null, doc4.Script, new object[] { locator });
// from now holds a reference 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.