Click here to Skip to main content
12,250,675 members (40,665 online)
Click here to Skip to main content

Stats

64.6K views
417 downloads
40 bookmarked
Posted

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

, 17 Apr 2006 CPOL
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 "workerthread.h"

DWORD WINAPI ThreadProc(LPVOID param)
{
	CThread *pThread = (CThread *)param;

	int Res = pThread->Run();

	return Res;
}


CThread::CThread()
{
	m_hEventTrigger		= ::CreateSemaphore(NULL, 0, 1, NULL);
	m_hEventStop		= ::CreateEvent(NULL,FALSE,FALSE,NULL);
	m_hEventFinished	= ::CreateEvent(NULL,FALSE,FALSE,NULL);
};

CThread::~CThread()
{
	// Stop thread
	SetEvent(m_hEventStop);

	// Keep object alive until thread gone
	::WaitForSingleObject(m_hEventFinished, INFINITE);

	::CloseHandle(m_hThread);
}

int CThread::BeginThread()
{
	m_hThread = ::CreateThread(NULL,0,ThreadProc,(LPVOID)this,CREATE_SUSPENDED,&m_nThreadID);

//	int t = CeGetThreadPriority(m_hThread);
//	BOOL b = CeSetThreadPriority(m_hThread, 50);
	
	DWORD r = ::ResumeThread(m_hThread);
	return 0;
}

int CThread::Run(void)
{
	bool bDone = FALSE;

	while (!bDone)
	{
		HANDLE parrEvents[] = { m_hEventTrigger, m_hEventStop };
		DWORD result = ::WaitForMultipleObjects(sizeof(parrEvents)/sizeof(HANDLE),parrEvents,FALSE,INFINITE);
		switch (result)
		{
			case WAIT_OBJECT_0 + 0: 
				{
					DoWork();
				} break;
			case WAIT_OBJECT_0 + 1: bDone = TRUE; break;
			default: 
				{
					LPVOID lpMsgBuf;
					DWORD err = GetLastError();
					FormatMessage( 
						FORMAT_MESSAGE_ALLOCATE_BUFFER | 
						FORMAT_MESSAGE_FROM_SYSTEM | 
						FORMAT_MESSAGE_IGNORE_INSERTS,
						NULL,
						err,
						0, // Default language
						(LPTSTR) &lpMsgBuf,
						0,
						NULL 
					);
					MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION );
					LocalFree(lpMsgBuf);

					bDone = TRUE; 
				} break;
		}
	}

	// Signal we are finished here and we are no longer accessing member data or methods
	::SetEvent(m_hEventFinished);

	return 0;
}

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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 17 Apr 2006
Article Copyright 2006 by Werner Willemsens
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid