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

A comprehensive CE class library to replace ATL and MFC

, 4 Oct 2000
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.
kgwince-old.zip
WinCe
BeamEx
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
Install
BeamEx.inf
BeamEx.ini
BeamEx.MIPS_PPCBW.CAB
BeamEx.MIPS_PPCColor.CAB
BeamEx.SH3_PPCColor.CAB
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeLib
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.old
CeLib.plg
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
dbView
bitmap1.bmp
bmp00001.bmp
db5.bmp
dbView.aps
DbView.dsp
dbView.dsw
dbView.old
dbView.plg
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
Install
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
mssccprj.scc
vssver.scc
ftpView
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
FtpView.old
ftpView.plg
FtpView.vcl
FtpView.vcp
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
Install
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
options.bmp
options1.bmp
seperato.bmp
vssver.scc
Setup
ico101.ico
Setup.aps
Setup.dsp
setup.ico
Setup.plg
WinCe.dsw
WinLib.dsw
kgwince.zip
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
BeamEx.vcl
BeamEx.vcp
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
BeamEx.inf
BeamEx.ini
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeFtp.vcp
CeFtp.vcw
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.plg
CeLib.vcl
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
bitmap1.bmp
bitmap2.bmp
bmp00001.bmp
db5.bmp
DbView.dsp
dbView.dsw
dbView.plg
DbView.vcl
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
menu1_5.bmp
mssccprj.scc
vssver.scc
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
ftpView.plg
FtpView.vcl
FtpView.vcp
FtpView.vcw
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
newmenu.bmp
options.bmp
options1.bmp
rcdata1.bin
seperato.bmp
toolbar1.bmp
vssver.scc
WinCe.dsw
WinCe.vcw
#ifndef __CeDb_h__
#define __CeDb_h__

#include "CeDebug.h"
#include "CeMisc.h"
#include "CeString.h"

#ifdef _WIN32_WCE
# include <windbase.h>
#else
# include <ole2.h>
# include <rapi.h>
#endif

class CeDbEnum;
class CeDb;
class CeDbRecord;
class CeDbProp;


///////////////////////////////////////////////////////////////////////////////
//
// Get/Manipulate the properties of a database data record
//
///////////////////////////////////////////////////////////////////////////////

//
// Property types
//
// CEVT_BLOB		A CEBLOB structure. 
// CEVT_FILETIME	A FILETIME structure. 
// CEVT_I2			A 16-bit signed integer. 
// CEVT_I4			A 32-bit signed integer. 
// CEVT_LPWSTR		A null-terminated string. 
// CEVT_UI2			A 16-bit unsigned integer. 
// CEVT_UI4			A 32-bit unsigned integer. 
//
// And beginning in 2.11
// CEVT_BOOL		A boolean value.
// CEVT_R8			A double floating point value.
//

class CeDbRecord
{
protected:
	friend class CeDb;

public:
	CEOID m_oid;			// the OID of the record
	WORD m_wProps;			// number of properties
	DWORD m_cbProps;		// the size of the allocated array
	CEPROPVAL* m_pProps;	// array of allocated field values
	bool m_bLocalAlloc;

protected:
	int FindProp(WORD wProp) const
	{
		for (int ii = 0; ii < (int) m_wProps; ii++)
		{
			if (HIWORD(m_pProps[ii].propid) == wProp)
				return ii;
		}
		return -1;
	}
	CEPROPVAL* DupProps(CEPROPVAL* pPropsOrig, WORD wProps, DWORD cbNewProps);

public:
	CeDbRecord()
		{
			m_oid = 0;
			m_wProps = 0;
			m_cbProps = 0;
			m_pProps = NULL;
			m_bLocalAlloc = false;
		}

	bool AddProp(WORD wProp, WORD wType);
	bool RemProp(int nCol);
	bool RemProp(WORD wId);

	// Get/Set value by identifier
	bool GetIdVal(WORD wProp, SHORT& iProp) const
		{ return GetIndexVal(FindProp(wProp), iProp); }

	bool GetIdVal(WORD wProp, USHORT& uiProp) const
		{ return GetIndexVal(FindProp(wProp), uiProp); }

	bool GetIdVal(WORD wProp, LONG& lProp) const
		{ return GetIndexVal(FindProp(wProp), lProp); }

	bool GetIdVal(WORD wProp, ULONG& ulProp) const
		{ return GetIndexVal(FindProp(wProp), ulProp); }

	bool GetIdVal(WORD wProp, FILETIME& ftProp) const
		{ return GetIndexVal(FindProp(wProp), ftProp); }

	bool GetIdVal(WORD wProp, CEBLOB& blobProp) const
		{ return GetIndexVal(FindProp(wProp), blobProp); }

	bool GetIdVal(WORD wProp, CeString& strProp) const
		{ return GetIndexVal(FindProp(wProp), strProp); }
#ifdef CEVT_BOOL
	bool GetIdVal(WORD wProp, bool& bProp) const
		{ return GetIndexVal(FindProp(wProp), bProp); }
#endif
#ifdef CEVT_R8
	bool GetIdVal(WORD wProp, double& dblProp) const
		{ return GetIndexVal(FindProp(wProp), dblProp); }
#endif

	bool SetIdVal(WORD wProp, SHORT sProp)
		{ return SetIndexVal(FindProp(wProp), sProp); }
	bool SetIdVal(WORD wProp, USHORT sProp)
		{ return SetIndexVal(FindProp(wProp), sProp); }
	bool SetIdVal(WORD wProp, LONG nProp)
		{ return SetIndexVal(FindProp(wProp), nProp); }
	bool SetIdVal(WORD wProp, ULONG dwProp)
		{ return SetIndexVal(FindProp(wProp), dwProp); }
	bool SetIdVal(WORD wProp, FILETIME ftProp)
		{ return SetIndexVal(FindProp(wProp), ftProp); }
	bool SetIdVal(WORD wProp, CEBLOB blobProp)
		{ return SetIndexVal(FindProp(wProp), blobProp); }
	bool SetIdVal(WORD wProp, LPCWSTR lpszProp)
		{ return SetIndexVal(FindProp(wProp), lpszProp); }
#ifdef CEVT_BOOL
	bool SetIdVal(WORD wProp, bool bProp)
		{ return SetIndexVal(FindProp(wProp), bProp); }
#endif
#ifdef CEVT_R8
	bool SetIdVal(WORD wProp, double dblProp)
		{ return SetIndexVal(FindProp(wProp), dblProp); }
#endif

	// Get/Set value by index
	bool GetIndexVal(int nProp, SHORT& iProp) const;
	bool GetIndexVal(int nProp, USHORT& uiProp) const;
	bool GetIndexVal(int nProp, LONG& lProp) const;
	bool GetIndexVal(int nProp, ULONG& ulProp) const;
	bool GetIndexVal(int nProp, FILETIME& ftProp) const;
	bool GetIndexVal(int nProp, CEBLOB& blobProp) const;
	bool GetIndexVal(int nProp, CeString& strProp) const;	// valid for all types, limited to 256 bytes for Blobs
#ifdef CEVT_BOOL
	bool GetIndexVal(int nProp, bool& bProp) const;
#endif
#ifdef CEVT_R8
	bool GetIndexVal(int nProp, double& dblProp) const;
#endif

	bool SetIndexVal(int nProp, SHORT iProp);
	bool SetIndexVal(int nProp, USHORT uiProp);
	bool SetIndexVal(int nProp, LONG lProp);
	bool SetIndexVal(int nProp, ULONG ulProp);
	bool SetIndexVal(int nProp, FILETIME ftProp);
	bool SetIndexVal(int nProp, CEBLOB blobProp);
	bool SetIndexVal(int nProp, LPCWSTR lpszProp);
#ifdef CEVT_BOOL
	bool SetIndexVal(int nProp, bool bProp);
#endif
#ifdef CEVT_R8
	bool SetIndexVal(int nProp, double dblProp);
#endif

	virtual ~CeDbRecord()
	{
		if (NULL != m_pProps)
			delete[] (BYTE*) m_pProps;
	}

protected:
	// record objects cannot be copied or assigned
	CeDbRecord(const CeDbRecord& arSrc);
	void operator=(const CeDbRecord& arSrc);
};


///////////////////////////////////////////////////////////////////////////////
//
// Create/Open/Delete/Modify a specific database
//
///////////////////////////////////////////////////////////////////////////////

class CeDb
{
private:
	HANDLE m_hDb;
	CEOID m_oid;
	WCHAR m_szName[256];

public:
// Construction
	CeDb()
		{ m_oid = 0; m_hDb = (HANDLE) INVALID_HANDLE_VALUE; *m_szName = 0; }

	bool Create(LPCWSTR lpszName, DWORD dwDbaseType = 0, WORD wNumSortOrder = 0, SORTORDERSPEC * rgSortSpecs = NULL)
		{
			m_oid = ::CeCreateDatabase((LPWSTR)lpszName, dwDbaseType, wNumSortOrder, rgSortSpecs); 
			wcscpy(m_szName, lpszName);
			return (m_oid) ? true: false;
		}
/*
	bool Open(CEPROPID idKey = 0, DWORD dwFlags = 0, HWND hwndNotify = NULL)
		{
			ASSERT(0 == m_oid);
			ASSERT(0 == *m_szName);
			ASSERT((HANDLE)INVALID_HANDLE_VALUE == m_hDb);

			// open from non-zero OID, assert handle null
			m_oid = 0;
			m_hDb = ::CeOpenDatabase (&m_oid, m_szName, idKey, dwFlags, hwndNotify);
			return (HANDLE)INVALID_HANDLE_VALUE != m_hDb;
		}
*/
	bool Open(CEOID oid = 0, CEPROPID idKey = 0, DWORD dwFlags = 0, HWND hwndNotify = NULL)
		{
			ASSERT((HANDLE)INVALID_HANDLE_VALUE == m_hDb);
			if (0 == oid)
			{
				ASSERT(0 != m_oid);
			}
			else
			{
				ASSERT(0 == *m_szName);
				//ASSERT(0 == m_oid);
				m_oid = oid;
			}

			// open from OID passed, assert handle null
			m_hDb = ::CeOpenDatabase (&m_oid, m_szName, idKey, dwFlags, hwndNotify);
			return ((HANDLE)INVALID_HANDLE_VALUE != m_hDb);
		}

	bool Open(LPCWSTR lpszName, CEPROPID idKey = 0, DWORD dwFlags = 0, HWND hwndNotify = NULL)
		{
			ASSERT(0 == m_oid);
			ASSERT(0 == *m_szName);
			ASSERT((HANDLE)INVALID_HANDLE_VALUE == m_hDb);

			// open from name, assert handle null
			wcscpy(m_szName, lpszName);
			m_hDb = ::CeOpenDatabase (&m_oid, m_szName, idKey, dwFlags, hwndNotify);
			
			return ((HANDLE)INVALID_HANDLE_VALUE != m_hDb);
		}

// Attributes
	bool IsOpen() const
		{ return ((HANDLE)INVALID_HANDLE_VALUE != m_hDb); }

	// reads up all the current records properties
	bool ReadRec(CeDbRecord& rec);

	bool AddRec(CeDbRecord& rec)
		{
			ASSERT(rec.m_wProps > 0);
			ASSERT(NULL != rec.m_pProps);

			rec.m_oid = ::CeWriteRecordProps(
				m_hDb,	
				0,
				rec.m_wProps,
				rec.m_pProps);

			return (0 != rec.m_oid);
		}

	bool UpdateRec(CeDbRecord& rec)
		{
			ASSERT(0 != rec.m_oid);
			ASSERT(rec.m_wProps > 0);
			ASSERT(NULL != rec.m_pProps);

			CEOID oid = ::CeWriteRecordProps(
				m_hDb,	
				rec.m_oid,
				rec.m_wProps,
				rec.m_pProps);

			return (oid == rec.m_oid);
		}

// Operations
	// Raw seek
	CEOID Seek(DWORD dwSeekType, DWORD dwValue, DWORD* pdwIndex=NULL)
		{
			DWORD dwIndex;
			CEOID ceoid = ::CeSeekDatabase(m_hDb, dwSeekType, dwValue, &dwIndex);
			if (pdwIndex) *pdwIndex = dwIndex;
			return ceoid;
		}

	CEOID SeekRec(CEPROPVAL *pPV)
		{ return Seek(CEDB_SEEK_VALUEFIRSTEQUAL, (DWORD) pPV); }

	CEOID SeekEnd(int nOff = 0)
		{ return Seek(CEDB_SEEK_END, nOff);	}

	CEOID SeekBegin(int nOff = 0)
		{ return Seek(CEDB_SEEK_BEGINNING, nOff); }

	CEOID SeekCurrent(int nOff)
		{ return Seek(CEDB_SEEK_CURRENT, nOff); }

	CEOID SeekNext()
		{ return SeekCurrent(1); }

	CEOID SeekPrev()
		{ return SeekCurrent(-1); }

	CEOID SeekTo(CEOID oid)
		{ return Seek(CEDB_SEEK_CEOID, oid); }

	CEOID SeekFirst()
		{ return SeekBegin(); }

	CEOID SeekLast()
		{ return SeekEnd(); }

// Other operations
	BOOL SetInfo(CEDBASEINFO* pNewInfo)
		{ return ::CeSetDatabaseInfo(m_oid, pNewInfo); }

	BOOL SetLastModified(FILETIME ft)
		{
			CEDBASEINFO info;
			info.dwFlags = CEDB_VALIDMODTIME;
			info.ftLastModified = ft;
			return SetInfo(&info);
		}

	BOOL SetName(LPCWSTR lpszName)
		{
			CEDBASEINFO info;
			info.dwFlags = CEDB_VALIDNAME;
			wcsncpy(info.szDbaseName, lpszName, CEDB_MAXDBASENAMELEN);
			return SetInfo(&info);
		}

	BOOL SetDbaseType(DWORD dwType)
		{
			CEDBASEINFO info;
			info.dwFlags = CEDB_VALIDTYPE;
			info.dwDbaseType = dwType;
			return SetInfo(&info);
		}
	//BOOL SetSort(SORTORDERSPEC pSortSpec)
	//	{
	//		CEDBASEINFO info;
	//		info.dwFlags = CEDB_VALIDSORTSPEC;
	//		return SetInfo(&info);
	//	}

// Destruction
	BOOL Delete()
		{ return ::CeDeleteDatabase(m_oid);	}
	BOOL DeleteRecord(CEOID oid)
		{ return ::CeDeleteRecord(m_hDb, oid); }
	void Close()
		{
			if (INVALID_HANDLE_VALUE != m_hDb)
			{
				::CloseHandle(m_hDb);
				m_hDb = INVALID_HANDLE_VALUE;
			}
		}
	~CeDb()
		{ Close(); }

protected:
	// database objects cannot be copied or assigned
	CeDb(const CeDb& Src);
	void operator=(const CeDb& Src);
};

///////////////////////////////////////////////////////////////////////////////
//
// Enumerate through the system databases
//
///////////////////////////////////////////////////////////////////////////////

class CeDbEnum
{
private:
	HANDLE m_hEnum;
	CEOID m_oid;

	// ???
	bool m_bHaveInfo;
    CEOIDINFO m_oidinfo;

public:
	bool First(DWORD dwType = 0)
		{
			m_bHaveInfo = false;
			m_hEnum = ::CeFindFirstDatabase(dwType);
			m_oid = 0;
			return (INVALID_HANDLE_VALUE != m_hEnum);
		}

	bool Next(bool bGetInfo = true)
		{
			CHW_ASSERT(NULL != m_hEnum);
			m_bHaveInfo = false;
			m_oid = ::CeFindNextDatabase(m_hEnum);
			if (ERROR_NO_MORE_ITEMS == GetLastError())
				return false;
			if (bGetInfo)
				GetInfo();
			return true;
		}

	CEOID GetOid() const			{ return m_oid;	}

	bool GetInfo()
		{
			if (! m_bHaveInfo)
			{
				if (! ::CeOidGetInfo(m_oid, &m_oidinfo))
					return false;
				m_bHaveInfo = true;
			}
			return true;
		}

	bool GetInfo(CEDBASEINFO& dbInfo)
		{
			if (GetInfo())
			{
				memcpy(&dbInfo, &m_oidinfo.infDatabase, sizeof m_oidinfo.infDatabase);
				return true;
			}
			return false;
		}

	// only valid if GetInfo() called or true passed to Next()
	LPCWSTR GetName() const
		{ return m_oidinfo.infDatabase.szDbaseName; }

	DWORD GetFlags() const
		{ return m_oidinfo.infDatabase.dwFlags; }

	DWORD GetType() const
		{ return m_oidinfo.infDatabase.dwDbaseType; }

	WORD GetNumRecords() const
		{ return m_oidinfo.infDatabase.wNumRecords; }

	WORD GetNumSorts() const
		{ return m_oidinfo.infDatabase.wNumSortOrder; }

	DWORD GetSize() const
		{ return m_oidinfo.infDatabase.dwSize; }

	FILETIME GetModified() const
		{ return m_oidinfo.infDatabase.ftLastModified; }

	// SORTORDERSPEC rgSortSpecs[CEDB_MAXSORTORDER];

	CeDbEnum()
		{ m_hEnum = NULL; m_oid = NULL; }

	~CeDbEnum()
		{ if (NULL != m_hEnum) ::CloseHandle(m_hEnum); }

protected:
	// database objects cannot be copied or assigned
	CeDbEnum(const CeDbEnum& Src);
	void operator=(const CeDbEnum& Src);
};


#endif // __CeDb_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)

Share

About the Author

Kenny G

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 5 Oct 2000
Article Copyright 2000 by Kenny G
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid