Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Bringing DCOM remoting functionality to Windows CE and .NET CF2.0

, 17 Apr 2006
This article shows how to use DCOM on Windows CE 5.0. We will add full DCOM rich error information, and implement a DCOM interface between a Windows XP .NET 2.0 client and Windows CE DCOM server. With this code, it is possible to code .NET remoting alike functionality through DCOM interop.
////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2006 Werner Willemsens
//
////////////////////////////////////////////////////////////////////

// Gate.cpp : Implementation of CGate

#include "stdafx.h"
#include "Gate.h"
#include <comutil.h>
#include <comdef.h>
#include "StarGatePS.h"
#include "Error.h"

// CGate

CGate::CGate()
{
	m_ChevronCount = 0;
	for (int i=0; i<MAX_CHEVRON_COUNT; i++) m_ChevronEntered[i] = 0;

	::InitializeCriticalSection(&m_ChevronProtect);
}

CGate::~CGate()
{
	::DeleteCriticalSection(&m_ChevronProtect);
}

STDMETHODIMP CGate::InterfaceSupportsErrorInfo(REFIID riid)
{
	// We will only arrive here when ISupportErrorInterface is properly marshalled
	// so Proxy/Stub code needs to be available
	static const IID* arr[] = 
	{
		&IID_IGate
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

void CGate::ProcessOpened(VARIANT *aValue)
{
	// Call the next function if you don't want the events to be sent via a seperate workerthread
//	DoFire_Opened(aValue);

	// Call the next function if you want the events to be sent via a seperate workerthread
	Fire_Opened(aValue);
}

STDMETHODIMP CGate::DialGate(LONG Chevron)
{
	HRESULT hr = S_OK;

	// Start protecting members
	::EnterCriticalSection(&m_ChevronProtect);

	if (m_ChevronCount < MAX_CHEVRON_COUNT)
		if ((0 <= Chevron) && (Chevron <= MAX_CHEVRON_SYMBOL))
			m_ChevronEntered[m_ChevronCount++] = Chevron;
		else
			hr = ThrowCOMError(CLSID_Gate, IID_IGate, IDS_E_INVALID_CHEVRON_SYMBOL);
	else
		hr = ThrowCOMError(CLSID_Gate, IID_IGate, IDS_E_TOO_MANY_CHEVRONS);
	long ChevronCount = m_ChevronCount;

	// Stop protecting members
	::LeaveCriticalSection(&m_ChevronProtect);

	if ((hr == S_OK) && (ChevronCount > MIN_CHEVRON_COUNT))
	{
		_bstr_t destination(_T("P"));
		for (int i=0; i<ChevronCount; i++)
			destination += _bstr_t(_variant_t(m_ChevronEntered[i]));

		ProcessOpened(&_variant_t(destination));
	}

	return hr;
}

STDMETHODIMP CGate::CloseGate()
{
	// Start protecting members
	::EnterCriticalSection(&m_ChevronProtect);

	m_ChevronCount = 0;

	// Stop protecting members
	::LeaveCriticalSection(&m_ChevronProtect);

	ProcessOpened(&_variant_t(_bstr_t(_T(""))));

	return S_OK;
}

STDMETHODIMP CGate::get_IsOpen(VARIANT_BOOL* pVal)
{
	// Start protecting members
	::EnterCriticalSection(&m_ChevronProtect);

	if (m_ChevronCount >= MAX_CHEVRON_COUNT) *pVal = VARIANT_TRUE;
	else *pVal = VARIANT_FALSE;

	// Stop protecting members
	::LeaveCriticalSection(&m_ChevronProtect);

	return S_OK;
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Werner Willemsens
Team Leader
Belgium Belgium
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 17 Apr 2006
Article Copyright 2006 by Werner Willemsens
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid