I have embedded a web browser control in my c++ application. I want javascript running in the web browser control to be able to call a c++ function/method.
I have fo
You need to implement GetIDsOfNames()
to do something sensible as that function will be called by client code before Invoke()
.
If you have your interfaces in a type library see here for an example. If you want to use late-binding instead, you can use DISPIDs greater DISPID_VALUE
and less than 0x80010000
(all values <= 0
and in the range 0x80010000
through 0x8001FFFF
are reserved):
HRESULT GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames,
LCID lcid, DISPID *rgDispId)
{
HR hr = S_OK;
for (UINT i=0; i<cNames; ++i) {
if (validName(rgszNames)) {
rgDispId[i] = dispIdForName(rgszNames);
} else {
rgDispId[i] = DISPID_UNKNOWN;
hr = DISP_E_UNKNOWNNAME;
}
}
return hr;
}
HRESULT Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS *Params, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
UINT *puArgErr)
{
if (wFlags & DISPATCH_METHOD) {
// handle according to DISPID ...
}
// ...
Note that the DISPID
s are not supposed to change suddenly, so e.g. a static map
or constant values should be used.