Click here to Skip to main content
15,881,803 members
Articles / Mobile Apps / Windows Mobile

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

Rate me:
Please Sign up or sign in to vote.
4.93/5 (11 votes)
17 Apr 2006CPOL14 min read 96.8K   513   40  
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
//
////////////////////////////////////////////////////////////////////

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

extern HINSTANCE g_hInstance;

HRESULT ThrowCOMError(const CLSID &clsid, const IID &iid, ULONG nErrorCode)
{
	// Who am I?
	_bstr_t sComponent;
    LPOLESTR sProgId;
    ProgIDFromCLSID(clsid, &sProgId);
    if (sProgId != NULL)
    {
        sComponent = sProgId;
        CoTaskMemFree (sProgId);
    }

	// Load string from resource
	TCHAR sString[256];
	int nLength = LoadString (g_hInstance, nErrorCode, sString, sizeof(sString));
	_bstr_t sDescription (sString);

	// Create rich error information
	ICreateErrorInfoPtr iCreateErrorInfo;
	if (SUCCEEDED(CreateErrorInfo (&iCreateErrorInfo)))
	{
		iCreateErrorInfo->SetGUID (iid);
		iCreateErrorInfo->SetSource (sComponent);
		iCreateErrorInfo->SetDescription (sDescription);
		iCreateErrorInfo->SetHelpFile (_bstr_t(_T("No helpfile")));
		iCreateErrorInfo->SetHelpContext (0x1234);

		IErrorInfoPtr iErrorInfo (iCreateErrorInfo);
		// Store rich error in local thread context, where it will be picked up
		// by IChannelHook...
		SetErrorInfo (0, iErrorInfo);
	}

	// Make a valid COM error HRESULT
	HRESULT hr = MAKE_HRESULT(3, FACILITY_ITF, nErrorCode);

	return hr;
};

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)


Written By
Team Leader
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions