您所在的位置: 首页>>开发>>语言&工具>>

VC++实现COM事件接收器

http://developer.51cto.com  2005-09-22 11:40  sinall  http://blog.csdn.net/sinall/  我要评论(0)
  • 摘要:本文介绍了VC++实现COM事件接收器的代码
  • 标签:C

1、给程序添加ATL支持。

右键->New ATL Object

2、实现IDispEventImpl 接口。

//EventSink.h

#import "..\Server\Debug\Server.exe" raw_interface_only,no_namespace,named_guids

class  CEventSink :
public IDispEventImpl<0, CEventSink,&DIID__IObjEvents,&LIBID_SERVERLib, 1, 0>
{
public:
CEventSink()
{
}
public:
BEGIN_SINK_MAP(CEventSink)
SINK_ENTRY_EX(0, DIID__IObjEvents, 1, cbFunc01)
END_SINK_MAP()
STDMETHOD(cbFunc01)();
};

//EventSink.cpp

#include "stdafx.h"
#include "EventSink.h"

STDMETHODIMP CEventSink::cbFunc01()
{
AfxMessageBox("called by Event from dll Server !");

return S_OK;
}

3、连接对象

// ClientDlg.cpp : implementation file
//
#include "EventSink.h"

void CClientDlg::OnButton1()
{
// TODO: Add your control notification handler code here
::CoInitialize(NULL);
{
IObjPtr pObj;
CEventSink *pEventSink= new CEventSink;
pObj.CreateInstance(__uuidof(Obj));
pEventSink->DispEventAdvise(pObj);
pObj->Func01();
pEventSink->DispEventUnadvise(pObj);
delete pEventSink;
}
::CoUninitialize();
}


最优性价比组建无线网络
网络应用性能控管最佳实践
如何有效提升企业安全审计应用水平
华硕IDC绿色节能服务器推荐
思科认证之CCNP考试最新资料宝典
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 6.0完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有