#include "stdafx.h"
#include <afxdisp.h>
#include "Imp_Draw.h"
#include "Imp_DrawDlg.h"
#import <mqoa.dll> no_namespace
//#include "MQEventHandler.h"
BEGIN_DISPATCH_MAP(CMSMQEventHandler, CCmdTarget)
DISP_FUNCTION_ID(CMSMQEventHandler, "Arrived", 0, Arrived, VT_EMPTY, VTS_DISPATCH VTS_I4)
DISP_FUNCTION_ID(CMSMQEventHandler, "ArrivedError", 1, ArrivedError, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_I4)
END_DISPATCH_MAP()
CMSMQEventHandler::CMSMQEventHandler()
{
EnableAutomation();
dwMyCookie = 0;
pMyCP = NULL;
}
CMSMQEventHandler::~CMSMQEventHandler()
{
if (pMyCP)
{
pMyCP->Unadvise(dwMyCookie);
pMyCP->Release();
};
}
void CMSMQEventHandler::Arrived(IDispatch* pdispQueue, long lCursor)
{
CImp_DrawDlg* pDlg = (CImp_DrawDlg*) AfxGetApp()->m_pMainWnd;
pDlg->Arrived(pdispQueue, S_OK, lCursor);
}
void CMSMQEventHandler::ArrivedError(IDispatch* pdispQueue, long lErrorCode, long lCursor)
{
CImp_DrawDlg* pDlg = (CImp_DrawDlg*) AfxGetApp()->m_pMainWnd;
pDlg->Arrived(pdispQueue, lErrorCode, lCursor);
}
HRESULT CMSMQEventHandler::AdviseSource(IDispatch* pDispatch)
{
LPCONNECTIONPOINTCONTAINERpCPCont = NULL;
HRESULThr;
hr = pDispatch->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPCont);
if (FAILED(hr))
return hr;
hr = pCPCont->FindConnectionPoint(__uuidof(_DMSMQEventEvents), &pMyCP);
pCPCont->Release();
if (FAILED(hr))
return hr;
return pMyCP->Advise(GetIDispatch(TRUE), &dwMyCookie);
};