0

Does anyone know how you can call a method of a prototype in Javascript from C++?

I have an pointer to script IDispatch, and I can get the IDsOfNames for the prototype, but I can't find how to get the IDispatch of it's member function.

Say (pseudocode):

JSprototype foo
{
    method bar(baz);
}

I can get a valid DISPID of foo, but I don't know how to call bar(baz). Does anyone have an idea?

Coder
  • 3,695
  • 7
  • 27
  • 42

1 Answers1

0

That's what IDispatch::Invoke is for. You don't need a separate IDispatch for every function. However, you do need a DISPID of bar, and therefore an IDispatch of foo. That means you'll have to call iFoo->Invoke(DISPID_bar) and QueryInterface(IDispatch) the result.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Yes, MSHTML. But I don't have a IDispatch of foo, I cant Invoke0(Bar, Baz); All I have is a IDispatch of the whole script object, and I can get DISPID of foo. How do you convert DISPID to IDispatch? – Coder Feb 18 '11 at 08:25
  • Generally speaking you can just do a PROPERTYGET with the DISPID of foo to get the IDispatch for foo. – taxilian May 28 '11 at 06:17