Cannot trigger OnChange event from inspector's command bar combo box

T

tonyl

When I got the new inspector event, I will create a combo box and toolbar
to the commandbars on the inspector window. And try to add the OnChange
event using the call DispEventAdvise or AtlAdvise.
When I use DispEventAdvise, it return S_OK. however, no one trigger the call
OnChangeCommandBarComboBox.
When I use AtlAdvise, the call returns 0x80040200 which means there is CONNECT_E_NOCONNECTION
Error

Anyone knows how to solve it?

Thanx alot.
Tony

connect.h
========
class ATL_NO_VTABLE CConnect :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CConnect, &CLSID_Connect>,
.....
public IDispEventSimpleImpl<3,CConnect,&__uuidof(Outlook::InspectorsEvents)>,
public IDispEventSimpleImpl<4,CConnect,&__uuidof(Office::_CommandBarComboBoxEvents)>
{
public:
....
typedef IDispEventSimpleImpl</*nID =*/ 3,CConnect, &__uuidof(Outlook::InspectorsEvents)>
NewInspectorEvents;
typedef IDispEventSimpleImpl</*nID =*/ 4,CConnect, &__uuidof(Office::_CommandBarComboBoxEvents)>
CommandBarComboBoxEvents;


BEGIN_SINK_MAP(CConnect)
....
SINK_ENTRY_INFO(3, __uuidof(Outlook::InspectorsEvents),/*dispid*/ 0xf001,
OnNewInspector, &OnNewInspectorInfo) // new inspector
SINK_ENTRY_INFO(4, __uuidof(Office::_CommandBarComboBoxEvents),/*dispid*/
0x1, OnChangeCommandBarComboBox, &OnComboBoxChangeInfo) // new inspector
END_SINK_MAP()

....

void __stdcall OnNewInspector(IDispatch *lpInspector);
void __stdcall OnChangeCommandBarComboBox(IDispatch *lpCtrl);
};



connect.cpp
===========

.....
_ATL_FUNC_INFO OnNewInspectorInfo = {CC_STDCALL,VT_EMPTY,1, {VT_DISPATCH}};
_ATL_FUNC_INFO OnComboBoxChangeInfo = {CC_STDCALL,VT_EMPTY,1, {VT_DISPATCH}};


void __stdcall CConnect::OnNewInspector(IDispatch *lpInspector)
{
CComQIPtr<Outlook::_Inspector> spInspector(lpInspector);
CComPtr<Office::_CommandBars> spCmdBars;
spInspector->get_CommandBars(&spCmdBars);
VARIANT vTitle, vPos, vMenuBar, vTemp;
vTitle.bstrVal = CString("callist").AllocSysString();
vTitle.vt = VT_BSTR;
vPos.vt = VT_UI4;
vPos.ulVal = 1 ;

vTemp.boolVal = TRUE;
vTemp.vt = VT_BOOL;

vMenuBar.vt = VT_UI4;
vMenuBar.ulVal = 0;
CComPtr<Office::CommandBar> spCmdBar;
CComPtr<Office::CommandBarControls> spCmdBarCtrls;
CComPtr<Office::_CommandBarComboBox> spCmdBarCtrl;
hr = spCmdBars->Add(vTitle, vtMissing, vtMissing, vTemp, &spCmdBar);
if (hr != S_OK) {
log.format(CLogger::LOG_ERROR, "OnNewInspector: Add CmdBar Failure");
return;
}

hr = spCmdBar->get_Controls(&spCmdBarCtrls);
if (hr != S_OK) {
log.format(CLogger::LOG_ERROR, "OnNewInspector: Get CmdBar Controls Failure");
return;
}

VARIANT vType, vInt1, vBool;
vType.vt = VT_UI4;
vType.ulVal = 4; //MsoControlType::msoControlComboBox
vInt1.vt = VT_UI4;
vInt1.ulVal = 1;
hr = spCmdBarCtrls->Add(vType, vtMissing, vtMissing, vInt1, vInt1, (Office::CommandBarControl
**)&spCmdBarCtrl);
if (hr != S_OK) {
log.format(CLogger::LOG_ERROR, "OnNewInspector: Add CmdBar Control Failure");
return;
}

hr = AtlAdvise((IUnknown *)spCmdBarCtrl, (IUnknown*)(CommandBarComboBoxEvents
*)this, __uuidof(Office::_CommandBarComboBox), &(((CommandBarComboBoxEvents
*)this)->m_dwEventCookie));
m_cbxEvent.m_dwChangeEventCookie = ((CommandBarComboBoxEvents *)this)->m_dwEventCookie;
if(FAILED(hr)) {
log.format(CLogger::LOG_APP_DEBUG, "CCmdbarCbxEvent::Notify() ERROR: CCmdbarCbxEvent::DispEventAdvise
failed: 0x%x", hr);
//return;
}
}

void __stdcall CConnect::OnChangeCommandBarComboBox(IDispatch *lpCtrl)
{
CComQIPtr<Office::_CommandBarComboBox> spCbx(lpCtrl);
MessageBox(0, "combo box selected!!!", "info", 0);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top