Re: IOleCommandTarget implementation not called
I reduced my application down to something that illustrates the
failure.
It compiles as is in a VC8 console application.
I want to catch script errors in my own Exec method and ignore them.
What am I doing wrong ?
I imagine I'm doing something stupid so please be gentle - I'm mostly
new to ATL/COM.
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <iostream>
class ATL_NO_VTABLE embedIE :
public CComObjectRootEx< CComSingleThreadModel >,
public IDispatch,
public IOleCommandTarget
{
public:
BEGIN_COM_MAP( embedIE )
COM_INTERFACE_ENTRY( IDispatch )
COM_INTERFACE_ENTRY_IID( DIID_DWebBrowserEvents2, IDispatch )
COM_INTERFACE_ENTRY( IOleCommandTarget )
END_COM_MAP()
STDMETHOD( GetTypeInfoCount )(UINT* pctinfo)
{
return E_NOTIMPL;
}
STDMETHOD( GetTypeInfo )(UINT itinfo, LCID lcid, ITypeInfo**
pptinfo)
{
return E_NOTIMPL;
}
STDMETHOD( GetIDsOfNames )(REFIID riid, LPOLESTR* rgszNames, UINT
cNames, LCID lcid, DISPID* rgdispid)
{
return E_NOTIMPL;
}
STDMETHODIMP QueryStatus( const GUID* pguidCmdGroup, ULONG cCmds,
OLECMD prgCmds[], OLECMDTEXT* pCmdText )
{
std::cout << "embedIE::QueryStatus" << std::endl;
return S_OK;
}
STDMETHODIMP Exec( const GUID* pguidCmdGroup, DWORD nCmdID, DWORD
nCmdExecOpt, VARIANTARG* pvaIn, VARIANTARG* pvaOut )
{
std::cout << "embedIE::Exec" << std::endl;
return S_OK;
}
STDMETHODIMP Invoke( DISPID dispid, REFIID riid, LCID lcid, WORD
wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO*
pexcepinfo, UINT* puArgErr )
{
std::cout << "embedIE::Invoke - dispid = " << dispid <<
std::endl;
return S_OK;
}
};
CComModule _Module;
int main( int argc, char* argv[] )
{
CoInitialize( NULL );
AtlAxWinInit();
HWND hWndBrowser = CreateWindow( ATLAXWIN_CLASS, "http://
dsc.discovery.com/video/?
playerId 3711706&categoryId=1175888584&lineupId=15803052&titleId=1509264631",
WS_VISIBLE | WS_POPUP | WS_VISIBLE, 0, 0, 512, 512, NULL, NULL, NULL,
NULL );
CComQIPtr< IViewObject > embeddedObject;
AtlAxGetControl( hWndBrowser, (IUnknown**)&embeddedObject );
DWORD cookie;
CComObject < embedIE >* embeddedBrowserHandler;
CComObject< embedIE >::CreateInstance( &embeddedBrowserHandler );
AtlAdvise( embeddedObject, embeddedBrowserHandler->GetUnknown(),
DIID_DWebBrowserEvents2, &cookie );
MSG msg;
while ( GetMessage( &msg, 0, 0, 0 ) != 0 )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
};
CoUninitialize();
}