Click here to Skip to main content
15,893,644 members
Articles / Web Development / HTML

A Comprehensive CE Class Library to Replace ATL and MFC

Rate me:
Please Sign up or sign in to vote.
4.48/5 (14 votes)
4 Oct 2000CPOL 281.7K   998   70  
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
/////////////////////////////////////////////////////////////////////////////
//
// RASUtil.h : classes wrapping the functionality of the RAS API
//
/////////////////////////////////////////////////////////////////////////////

#ifndef __CeRas_h__
#define __CeRas_h__

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include <ras.h>		// Remote Access Service API
#include <raserror.h>	// RAS Error codes

#include "CeThread.h"		// critical section class
#include "CeMap.h"
#include "CeArray.h"
#include "CeString.h"

typedef CeArray<CeString> CeStringArray;

/////////////////////////////////////////////////////////////////////////////
// The classes in this file include:

class CeRasDevInfo;
class CeRasEntryName;
class CeRasEntry;
class CeRasDialParams;
class CeRasConn;
class CeRasDialExt;

class CeRasAmb;
class CeRasPppNbf;
class CeRasPppIpx;
class CeRasPppIp;

/////////////////////////////////////////////////////////////////////////////
// CeRasDevInfo
typedef RASDEVINFO _rasdevinfo;
class CeRasDevInfo : public _rasdevinfo
{
public:
	CeRasDevInfo()
	{
		memset((_rasdevinfo *)this, 0, sizeof _rasdevinfo);
		dwSize = sizeof(RASDEVINFO);
	}
	~CeRasDevInfo() {}

#ifndef _WIN32_WCE
	static int GetAll(RASDEVINFO** arDevInfo);
#endif

};

/////////////////////////////////////////////////////////////////////////////
// CeRasConnStatus
typedef RASCONNSTATUS _rasconnstatus;
class CeRasConnStatus : public _rasconnstatus
{
public:
	CeRasConnStatus()
	{
		memset((_rasconnstatus *)this, 0, sizeof _rasconnstatus);
		dwSize = sizeof(RASCONNSTATUS);
	}
	~CeRasConnStatus() {}
};

/////////////////////////////////////////////////////////////////////////////
// CeRasEntryName
typedef RASENTRYNAME _rasentryname;
class CeRasEntryName : public _rasentryname
{
public:
	CeRasEntryName()
	{
		memset((_rasentryname*)this, 0, sizeof _rasentryname);
		dwSize = sizeof _rasentryname;
	}
	~CeRasEntryName() {}
};


/////////////////////////////////////////////////////////////////////////////
// CeRasDialExt
typedef RASDIALEXTENSIONS _rasdialextensions;
class CeRasDialExt : public _rasdialextensions
{
public:
	CeRasDialExt(DWORD dwfOpt = 0, HWND hwnd = NULL)
	{
		memset((_rasdialextensions*)this, 0, sizeof _rasdialextensions);
		dwSize = sizeof _rasdialextensions;
		dwfOptions = dwfOpt;
		hwndParent = hwnd;

	}
	~CeRasDialExt() {}

	DWORD GetOptions() const { return dwfOptions; }
	void  SetOptions(DWORD dwfOpt) { dwfOptions = dwfOpt; }

	HWND GetParentHWnd() const { return hwndParent; }
	void SetParentHWnd(HWND hwnd) { hwndParent = hwnd; }
};


/////////////////////////////////////////////////////////////////////////////
// CeRasAmb
typedef RASAMB _rasamb;
class CeRasAmb : public _rasamb
{
public:
	CeRasAmb()
	{
		memset((_rasamb *)this, 0, sizeof _rasamb);
		dwSize = sizeof _rasamb;
	}
	~CeRasAmb() {}
};

/////////////////////////////////////////////////////////////////////////////
// CeRasPppNbf
typedef RASPPPNBF _raspppnbf;
class CeRasPppNbf : public _raspppnbf
{
public:
	CeRasPppNbf()
	{
		memset((_raspppnbf *)this, 0, sizeof _raspppnbf);
		dwSize = sizeof(RASPPPNBF);
	}
	~CeRasPppNbf() {}
};

/////////////////////////////////////////////////////////////////////////////
// CeRasPppIpx
typedef RASPPPIPX _raspppipx;
class CeRasPppIpx : public _raspppipx
{
public:
	CeRasPppIpx()
	{
		memset((_raspppipx *)this, 0, sizeof _raspppipx);
		dwSize = sizeof(RASPPPIPX);
	}
	~CeRasPppIpx() {}
};

/////////////////////////////////////////////////////////////////////////////
// CeRasPppIp
typedef RASPPPIP _raspppip;
class CeRasPppIp : public _raspppip
{
public:
	CeRasPppIp()
	{
		memset((_raspppip *)this, 0, sizeof _raspppip);
		dwSize = sizeof(RASPPPIP);
	}
	~CeRasPppIp() {}
};

/////////////////////////////////////////////////////////////////////////////
// CeRasEntry
typedef RASENTRY _rasentry;
class CeRasEntry : public _rasentry
{
public:
	CeRasEntry(LPCTSTR lpszDevName=NULL, LPCTSTR lpszPhone=NULL, LPCTSTR lpszAreaCode=NULL, LPCTSTR lpszCountryCode=NULL);
	~CeRasEntry();

	// get/set entry using this object
	void Create(LPCTSTR szName);
	void Get(LPCTSTR szName, LPBYTE* lpbDevInfo = NULL);
	void Set(LPCTSTR szName, LPBYTE lpbDevInfo = NULL);

#ifndef _WIN32_WCE
	void SetWin95(LPCTSTR szName);
#endif

	void SetDevice(LPCTSTR strDevName);
	void SetPhone(LPCTSTR strPhoneNumber, LPCTSTR  strAreaCode=NULL, LPCTSTR strCountryCode=NULL);

	static void Rename(LPCTSTR szNameTo, LPCTSTR szNameFrom);
	static void Delete(LPCTSTR szName);

	static int GetAll(RASENTRYNAME** arEntries);

	static long StringToIP(LPCTSTR szIP);
	static RASIPADDR StringToRASIP(LPCTSTR strIP);

private:
	static void IPHelper();

	CeStringArray m_arAdditional;
};

/////////////////////////////////////////////////////////////////////////////
// CeRasDialParams
typedef RASDIALPARAMS _rasdialparams;
class CeRasDialParams : public _rasdialparams
{
public:
	CeRasDialParams(LPCTSTR lpszEntry, LPCTSTR lpszUserName, LPCTSTR lpszPassword)
	{
		memset((_rasdialparams*)this, 0, sizeof _rasdialparams);
		dwSize = sizeof _rasdialparams;
		_tcscpy(szEntryName, lpszEntry);
		_tcscpy(szUserName, lpszUserName);
		_tcscpy(szPassword, lpszPassword); 
	}
	~CeRasDialParams() {}

	// Note that the default copy constructor is just dandy
};


typedef RASCONN _rasconn;
class CeRasConn : public _rasconn
{
protected:
	//
	// Monitors asynchronous connections automatically
	//
	class CeRasConnMapper
	{
	private:
		CeCriticalSection m_cs;
		//CeSimpleMap<HRASCONN, CeRasConn*> m_mapConn;
		CeSimpleMap<HRASCONN, void*> m_mapConn;

	public:
		BOOL AddMapping(HRASCONN hRASConn, CeRasConn* pConn)
		{
			m_cs.Enter();
			m_mapConn.Add(hRASConn, pConn);
			m_cs.Leave();

			return TRUE;
		}

		CeRasConn* GetMapping(HRASCONN hRASConn)
		{
			m_cs.Enter();
			CeRasConn* pConn = (CeRasConn *) m_mapConn.Lookup(hRASConn);
			m_cs.Leave();

			return pConn;
		}

		CeRasConn* RemoveMapping(HRASCONN hRASConn)
		{
			m_cs.Enter();
			CeRasConn* pConn = (CeRasConn*) m_mapConn.Lookup(hRASConn);
			if (NULL != pConn)
				m_mapConn.Remove(hRASConn);
			m_cs.Leave();

			return pConn;
		}
	};

	static CeRasConnMapper s_mapConn;

public:
	// DECLARE_DYNAMIC(CeRasConn)

	CeRasConn();
	virtual ~CeRasConn();

	DWORD SetTimeout(DWORD dwMilliseconds)
		{
			DWORD dwOld = m_dwTimeOut;
			m_dwTimeOut = dwMilliseconds;
			return dwOld;
		}
	DWORD GetTimeout() const
		{ return m_dwTimeOut; }

	int SetRetries(int nRetries)
		{
			int nOld = m_nRetries;
			m_nRetries = nRetries;
			return nOld;
		}
	DWORD GetRetries() const
		{ return m_nRetries; }

	void Dial(LPRASDIALPARAMS lpRasDialParams, BOOL bSynchronous=TRUE, LPRASDIALEXTENSIONS lpRASDialExt=NULL);
	void Hangup(BOOL bSynchronous=TRUE);

	static CeString GetStatus(RASCONNSTATE rasconnstate);
	DWORD GetStatus(CeRasConnStatus& rasState);
	CeString GetStatus();
	BOOL IsConnected();

#if !defined(_WIN32_WCE)
	void GetProjectionInfo(LPRASAMB pInfo);
	void GetProjectionInfo(LPRASPPPNBF pInfo);
	void GetProjectionInfo(LPRASPPPIPX pInfo);
	void GetProjectionInfo(LPRASPPPIP pInfo);
#endif

	static VOID WINAPI RasDialNotificationFn(HRASCONN hrasconn, UINT unMsg, RASCONNSTATE rascs, DWORD dwError, DWORD dwExtendedError);
	virtual void OnDialStatus(UINT unMsg, RASCONNSTATE rascs, DWORD dwError, DWORD dwExtendedError);
	virtual void LogEvent(short nPriority, LPCTSTR szEvent) const;

	static int GetAll(RASCONN** arConn);

	BOOL IsDialComplete() const
		{ return m_bComplete; }
	void SetDialComplete(DWORD dwError);
	void WaitForDialComplete();

#ifdef _DEBUG
//	virtual void AssertValid( ) const;
//	virtual void Dump( CDumpContext& dc ) const;
#endif

private:
	// Dialing parameters for active call
//	LPTSTR m_lpszPhoneBook;
	LPRASDIALPARAMS m_lpRasDialParams;
	BOOL m_bSynchronous;

	// Connection complete status
	BOOL m_bComplete;

	// Event used to make WaitForConnect() work
	CeManualEvent m_eventDialComplete;

	// Dialing status for active dial
	UINT m_unMsg;
	RASCONNSTATE m_rascs;
	DWORD m_dwError;
	DWORD m_dwExtendedError;
	DWORD m_dwTimeOut;
	int m_nRetries;
};

#endif // __CeRas_h__

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
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