VC中响应COM组件的事件失败,高分求助高人啊!!

Python Python 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有一个普通的COM组件,其中有两个事件,我想在MFC Dialog中使用该组件并响应其事件,我生成了一个事件响应类,并实现了接口,该类程序全部由VC 2010自动生成,代码如下:
// DSSimpleObjSink.h : Declaration of the CDSSimpleObjSink

#pragma once
#include "resource.h" // main symbols



#include "Test in VC_i.h"



#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;


// CDSSimpleObjSink

class ATL_NO_VTABLE CDSSimpleObjSink :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CDSSimpleObjSink, &CLSID_DSSimpleObjSink>,
public IDispatchImpl<IDSSimpleObjSink, &IID_IDSSimpleObjSink, &LIBID_TestinVCLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IDispatchImpl<_IDSSimpleObjEvents, &__uuidof(_IDSSimpleObjEvents), &LIBID_DataEngineTestLib, /* wMajor = */ 1>
{
public:
CDSSimpleObjSink()
{
}

DECLARE_REGISTRY_RESOURCEID(IDR_DSSIMPLEOBJSINK)

DECLARE_NOT_AGGREGATABLE(CDSSimpleObjSink)

BEGIN_COM_MAP(CDSSimpleObjSink)
COM_INTERFACE_ENTRY(IDSSimpleObjSink)
COM_INTERFACE_ENTRY2(IDispatch, _IDSSimpleObjEvents)
COM_INTERFACE_ENTRY(_IDSSimpleObjEvents)
END_COM_MAP()


DECLARE_PROTECT_FINAL_CONSTRUCT()

HRESULT FinalConstruct()
{
return S_OK;
}

void FinalRelease()
{
}

public:


// _IDSSimpleObjEvents Methods
public:
STDMETHOD(UpdateUI)(long BusinessID)
{
int i = BusinessID;
return 1;
}
STDMETHOD(PrePrint)(BSTR * PrintContent)
{
int i = 0;
return 1;
}
};

OBJECT_ENTRY_AUTO(__uuidof(DSSimpleObjSink), CDSSimpleObjSink)


我在Dialog中使用方法如下:
	HRESULT hr = CoCreateInstance(CLSID_DSSimpleObj, NULL, CLSCTX_INPROC_SERVER,
IID_IDSSimpleObj, (LPVOID*)&m_pDSSimpleObj);

if (FAILED(hr))
{
m_pDSSimpleObj = 0;

MessageBox(_T("Create DSSimpleObj failed."));

return false;
}

//CComPtr<IConnectionPoint> pPC;
CComQIPtr<IConnectionPointContainer, &__uuidof(IConnectionPointContainer)> pCPC(m_pDSSimpleObj);
pCPC->FindConnectionPoint(DIID__IDSSimpleObjEvents, &m_pPC);

CComPtr<IUnknown> pUnk;
//CDSSimpleObjSink* pDSSimpleObjEvent = new CComObject<CDSSimpleObjSink>;
m_pDSSimpleObjEvent = new CComObject<CDSSimpleObjSink>;
m_pDSSimpleObjEvent->QueryInterface(IID_IUnknown, (void**)&pUnk);
m_pPC->Advise(pUnk, &m_dwCookie);


其中声明如下:
	CComPtr<IDSSimpleObj> m_pDSSimpleObj;
DWORD m_dwCookie;
CDSSimpleObjSink* m_pDSSimpleObjEvent;
CComPtr<IConnectionPoint> m_pPC;


调试时,发现函数UpdateUI或者PrePrint都没有进入,不知怎么回事,请高人帮帮忙啊,谢谢啦!!
...全文
评论 20
收藏 已收藏
分享
返回顶部
Python
ATL 3,248 成员 48,530 内容