Click here to Skip to main content
15,895,709 members
Articles / Desktop Programming / WTL

Passing C++ classes across DCOM

Rate me:
Please Sign up or sign in to vote.
4.64/5 (10 votes)
15 Nov 20012 min read 214.4K   2.5K   42  
Two classes that provide richer interfaces and easier semantics to pass classes via COM/DCOM
#if !defined(AFX_SERVERACCESSPOINT_H__70D2AF9B_3B70_4B39_B6C2_B617EE936ED9__INCLUDED_)
#define AFX_SERVERACCESSPOINT_H__70D2AF9B_3B70_4B39_B6C2_B617EE936ED9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ServerAccessPoint.h : header file
//

#include "../StreamingServer/StreamingServer.h"
#include "Connection.h"


#define IID_SERVER			IID_IStreamingSrv
#define CLSID_SERVER		CLSID_StreamingSrv
#define I_SERVER			IStreamingSrv

class CServerListener
{
public:
	virtual void OnServerConnectionChanged(CConnectionArray* pArray) = 0;
};

/////////////////////////////////////////////////////////////////////////////
// CServerAccessPoint command target

class CServerAccessPoint : public CCmdTarget
{
	DECLARE_DYNCREATE(CServerAccessPoint)

public:
// Constructor/destructor
	CServerAccessPoint();
	virtual ~CServerAccessPoint();

// Attributes
	void AddListener(CServerListener*pListener);
	void RemoveListener();

	bool IsValidServer();
	bool IsConnected();

	static 
	CServerAccessPoint*	GetServer();

	CConnectionArray	m_connections;

// Operations
public:
	bool ServerConnect(CConnection& connObj);
	void ServerDisconnect();
	void OnConnectionsChanged(VARIANT* pNewConnections);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CServerAccessPoint)
	//}}AFX_VIRTUAL

// Implementation
protected:

	void PumpMessage();
	void ShowError(CString text);
	void ShowServerError();

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

	DECLARE_MESSAGE_MAP()
	BEGIN_INTERFACE_PART(ConnectionSink,IConnectionSink)
		STDMETHOD(GetTypeInfoCount)(unsigned int*)
			{ return E_NOTIMPL; }
		STDMETHOD(GetTypeInfo)(unsigned int, LCID, ITypeInfo**)
			{ return E_NOTIMPL; }
		STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, unsigned int, LCID, DISPID*)
			{ return E_NOTIMPL; }
		STDMETHOD(Invoke)(DISPID, REFIID, LCID, unsigned short, DISPPARAMS*,
						  VARIANT*, EXCEPINFO*, unsigned int*)
			{ return E_NOTIMPL; }
		STDMETHOD(OnPropertyChanged)(VARIANT*pProperty);
		STDMETHOD(OnEvent)(VARIANT*pProperty);
	END_INTERFACE_PART(ConnectionSink)

	DECLARE_INTERFACE_MAP()

protected:

	CComPtr<IUnknown>	m_pUnkSink;
	DWORD				m_dwSinkCookie;
	I_SERVER*			m_pDcomServer;
	CConnection			m_connection;

	CServerListener*	m_pListener;

	static	
	CServerAccessPoint*	m_pServer;
};

inline void CServerAccessPoint::AddListener(CServerListener*pListener)
{
	m_pListener = pListener;
}

inline void CServerAccessPoint::RemoveListener()
{
	m_pListener = NULL;
}

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SERVERACCESSPOINT_H__70D2AF9B_3B70_4B39_B6C2_B617EE936ED9__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions