Send Event to JavaScript from ActiveX
I have an C++/Non-MFC out of proc ActiveX control that works great, and I
need to implement event triggering within my html page. Within my html page
I have:
<script language="javascript" type="text/javascript" For="MyObj"
Event="OnEvent(event_in,event_out)">
alert(event_in);
</script>
<object id="MyObj" name="MyObj"
classid="clsid:5189XXXX-00E7-4BF8-86F3-B8EF935A45E9"
style="display:none;"></object>
The html pages calls an API within my ActiveX control. The API then creates
a worker thread, and starts to process, and the api exits. Once the worker
thread is done executing, I need to trigger the OnEvent within my HTML page.
I have defined a connectionpoint within my IDL file that looks something
like this:
dispinterface _IOEvents
{
properties:
methods:
[id(1), helpstring("method OnEvent")] HRESULT OnEvent([in] BSTR
bstrMessage, [in] BSTR bstrTitle);
};
I then have the function Fire_OnEvent function defined within the Proxy
class and it looks like this:
HRESULT Fire_OnEvent( BSTR bstrMessage, BSTR bstrTitle)
{
HRESULT hr = S_OK;
T * pThis = static_cast<T *>(this);
int cConnections = m_vec.GetSize();
for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();
IDispatch * pConnection = static_cast<IDispatch *>(punkConnection.p);
if (pConnection)
{
CComVariant avarParams[2];
avarParams[1] = bstrMessage;
avarParams[1].vt = VT_BSTR;
avarParams[0] = bstrTitle;
avarParams[0].vt = VT_BSTR;
CComVariant varResult;
DISPPARAMS params = { avarParams, NULL, 2, 0 };
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
}
}
return hr;
}
the problem is the m_vec is always zero, and not sure where things are
breaking and why the callbck is not functioning. Can anybody help assist in
what I need to look at, and how I can confirm that IE is truely requesting
the event to be sent to the html window?
Thanks,
William