帮我分析一下MFC自动化服务器中连接点(即CallBack)的出错的原因。进来给分,不够可以在给。

etre 2004-02-12 02:43:56
我的服务器是一个MFC的自动化服务器,代码如下:
#ifndef _COM_INTERFACE_
#define _COM_INTERFACE_

// {81EE1E76-E2D6-4563-BC08-2CF75E8EF6AA}
static const IID IID_IHelloSpeaker =
{ 0x81ee1e76, 0xe2d6, 0x4563, { 0xbc, 0x8, 0x2c, 0xf7, 0x5e, 0x8e, 0xf6, 0xaa } };

// {3568227A-DD93-4d53-A172-BC26BF005F67}
static const IID IID_IHelloSpeaker3 =
{ 0x3568227a, 0xdd93, 0x4d53, { 0xa1, 0x72, 0xbc, 0x26, 0xbf, 0x0, 0x5f, 0x67 } };

/*
// {72B9B9A7-A0A7-4F1F-8CB8-8C243B5AAD3D}
static const IID CLSID_DispatchObject = //郪璃ID
{ 0x72b9b9a7, 0xa0a7, 0x4f1f, { 0x8c, 0xb8, 0x8c, 0x24, 0x3b, 0x5a, 0xad, 0x3d } };

*/
struct IHelloSpeaker:IUnknown
{
STDMETHOD_(void,SayHello)(BSTR bstrMsg) = 0 ;
};

struct IHelloSpeaker3:IUnknown
{
STDMETHOD_(void,SayHello)(BSTR bstrMsg) = 0 ;
};


#endif

class CDispatchServerDlgAutoProxy : public CCmdTarget
{
DECLARE_DYNCREATE(CDispatchServerDlgAutoProxy)

CDispatchServerDlgAutoProxy(); // protected constructor used by dynamic creation

// Attributes
public:
CDispatchServerDlg* m_pDialog;

// Operations
public:
void FireHelloEvent(BSTR bstrMsg);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDispatchServerDlgAutoProxy)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL

// Implementation
protected:
virtual ~CDispatchServerDlgAutoProxy();

// Generated message map functions
//{{AFX_MSG(CDispatchServerDlgAutoProxy)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
DECLARE_OLECREATE(CDispatchServerDlgAutoProxy)
DECLARE_DISPATCH_MAP()
DECLARE_CONNECTION_MAP()

BEGIN_INTERFACE_PART(HelloSpeaker,IHelloSpeaker)
INIT_INTERFACE_PART(CDispatchServerDlgAutoProxy, HelloSpeaker)
STDMETHOD_(void,SayHello)(BSTR bstrMsg);
END_INTERFACE_PART(HelloSpeaker)
BEGIN_CONNECTION_PART(CDispatchServerDlgAutoProxy, HelloSpeaker3Event)
CONNECTION_IID(IID_IHelloSpeaker3)
END_CONNECTION_PART(HelloSpeaker3Event)
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(CDispatchServerDlgAutoProxy)
afx_msg void SysHelloEvent();
//}}AFX_DISPATCH
DECLARE_INTERFACE_MAP()
};
IMPLEMENT_DYNCREATE(CDispatchServerDlgAutoProxy, CCmdTarget)

CDispatchServerDlgAutoProxy::CDispatchServerDlgAutoProxy()
{

EnableConnections();

EnableAutomation();

AfxOleLockApp();

ASSERT (AfxGetApp()->m_pMainWnd != NULL);
ASSERT_VALID (AfxGetApp()->m_pMainWnd);
ASSERT_KINDOF(CDispatchServerDlg, AfxGetApp()->m_pMainWnd);
m_pDialog = (CDispatchServerDlg*) AfxGetApp()->m_pMainWnd;
m_pDialog->m_pAutoProxy = this;
}

CDispatchServerDlgAutoProxy::~CDispatchServerDlgAutoProxy()
{
if (m_pDialog != NULL)
m_pDialog->m_pAutoProxy = NULL;
AfxOleUnlockApp();
}

void CDispatchServerDlgAutoProxy::OnFinalRelease()
{

CCmdTarget::OnFinalRelease();
}

BEGIN_MESSAGE_MAP(CDispatchServerDlgAutoProxy, CCmdTarget)
//{{AFX_MSG_MAP(CDispatchServerDlgAutoProxy)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CDispatchServerDlgAutoProxy, CCmdTarget)
//{{AFX_DISPATCH_MAP(CDispatchServerDlgAutoProxy)
DISP_FUNCTION(CDispatchServerDlgAutoProxy, "SysHelloEvent", SysHelloEvent, VT_EMPTY, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()



// {48314AAA-3CC5-485F-A065-CA1E9AFFF0F7}
static const IID IID_IDispatchServer =
{ 0x48314aaa, 0x3cc5, 0x485f, { 0xa0, 0x65, 0xca, 0x1e, 0x9a, 0xff, 0xf0, 0xf7 } };

BEGIN_INTERFACE_MAP(CDispatchServerDlgAutoProxy, CCmdTarget)
INTERFACE_PART(CDispatchServerDlgAutoProxy, IID_IHelloSpeaker, HelloSpeaker)
INTERFACE_PART(CDispatchServerDlgAutoProxy, IID_IDispatchServer, Dispatch)
INTERFACE_PART(CDispatchServerDlgAutoProxy, IID_IConnectionPointContainer, ConnPtContainer)
END_INTERFACE_MAP()

BEGIN_CONNECTION_MAP(CDispatchServerDlgAutoProxy, CCmdTarget)
CONNECTION_PART(CDispatchServerDlgAutoProxy, IID_IHelloSpeaker3, HelloSpeaker3Event)
END_CONNECTION_MAP()
// The IMPLEMENT_OLECREATE2 macro is defined in StdAfx.h of this project
// {72B9B9A7-A0A7-4F1F-8CB8-8C243B5AAD3D}
IMPLEMENT_OLECREATE2(CDispatchServerDlgAutoProxy, "DispatchServer.Application", 0x72b9b9a7, 0xa0a7, 0x4f1f, 0x8c, 0xb8, 0x8c, 0x24, 0x3b, 0x5a, 0xad, 0x3d)

STDMETHODIMP_(ULONG) CDispatchServerDlgAutoProxy::XHelloSpeaker::AddRef()
{
METHOD_PROLOGUE(CDispatchServerDlgAutoProxy, HelloSpeaker)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CDispatchServerDlgAutoProxy::XHelloSpeaker::Release()
{
METHOD_PROLOGUE(CDispatchServerDlgAutoProxy, HelloSpeaker)
return pThis->ExternalRelease() ;
}

STDMETHODIMP_(HRESULT) CDispatchServerDlgAutoProxy::XHelloSpeaker::QueryInterface(REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE(CDispatchServerDlgAutoProxy, HelloSpeaker)
return pThis->ExternalQueryInterface(&iid,ppvObj) ;
}


void CDispatchServerDlgAutoProxy::FireHelloEvent(BSTR bstrMsg)
{
//now check the connection Point
POSITION pos =m_xHelloSpeaker3Event.GetStartPosition();
IHelloSpeaker3* pHelloSpeaker3 = NULL;
while(pos != NULL)
{
pHelloSpeaker3 = (IHelloSpeaker3*)m_xHelloSpeaker3Event.GetNextConnection(pos);
ASSERT(pHelloSpeaker3);
TRY
TRACE0("Fire Hello Event...\n");
pHelloSpeaker3->SayHello(bstrMsg);
END_TRY
}
}
STDMETHODIMP_(void) CDispatchServerDlgAutoProxy::XHelloSpeaker::SayHello(BSTR bstrMsg)
{
METHOD_PROLOGUE(CDispatchServerDlgAutoProxy, HelloSpeaker)
CString s(bstrMsg);
pThis->FireHelloEvent(bstrMsg);

}
...全文
96 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧