Click here to Skip to main content
15,896,269 members
Articles / Mobile Apps / Windows Mobile

Enable floating SIP control in IPAQ/Windows CE .NET

Rate me:
Please Sign up or sign in to vote.
3.60/5 (5 votes)
10 Dec 2002CPOL2 min read 120.6K   176   23  
Enable floating SIP control in iPAQ/Windows CE .NET devices.
//***********************************************************
//					Registry Access Module				   //
//                                                         //
//                     Author : C. Chris                   //
//				  http://www.PassportONE.com			   //
//		         Email:  chris@PassportONE.com			   //
//                      � Oct/Apr 2001                     //
//                                                         //
//***********************************************************

#include "RegEdit.h"

//-----------------------------------------------------------
//
//	STRING
//
//-----------------------------------------------------------

BOOL SaveString (HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, LPCTSTR lpData)
{
	//  PURPOSE:  
	//		- Save the data into registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Save the given data into the given key and value name.
	//  RETURN VALUE:
	//      - 0		:: Fail
	//		  1		:: Pass

	//Registry Key Handle
	HKEY	CurKey;
	DWORD	dwDisposition=0;

	BOOL	fRes=false;

	// Sanity check
	if (lpszSubkey != NULL && lpszValueName != NULL)
	{
		// Sanity check
		if (_tcslen(lpszSubkey) > 0 && _tcslen(lpszValueName) > 0)
		{
			// OPen registry
			if (RegOpenKeyEx(lpszKey, lpszSubkey, 0, 0, &CurKey) == ERROR_SUCCESS)
			{
				// Update value
				if (RegSetValueEx(CurKey, lpszValueName, 0, REG_SZ, (PBYTE)lpData, _tcslen(lpData) * sizeof(LPCTSTR)) == ERROR_SUCCESS)
					fRes = true;
			}
			else
			{
				// Create new key
				if (RegCreateKeyEx(lpszKey, lpszSubkey, 0, 0, 0, 0, NULL, &CurKey, &dwDisposition) == ERROR_SUCCESS)
				{
					// UPdate value
					if (RegSetValueEx(CurKey, lpszValueName, 0, REG_SZ, (PBYTE)lpData, _tcslen(lpData) * sizeof(LPCTSTR)) == ERROR_SUCCESS)
						fRes = true;
				}
			}
		}
	}
	// Close the register
	RegCloseKey (CurKey);
	// Set the return value
	return fRes;
}

LPTSTR ReadString (HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, LPCTSTR pcDefault)
{
	//  PURPOSE:  
	//		- Read the data from registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Write the given data into the given key and value name.
	//  RETURN VALUE:
	//      - Value

	// Registry Key Handle
	HKEY	CurKey;
	DWORD	dwType = REG_SZ;
	DWORD	dwDataSize=0;;

	TCHAR	*lpszValue=NULL;


	// Sanity check
	if (lpszSubkey != NULL && lpszValueName != NULL)
	{
		// Sanity check
		if (_tcslen(lpszSubkey) > 0 && _tcslen(lpszValueName) > 0)
		{
			// Sanity check
			if (RegOpenKeyEx(lpszKey, lpszSubkey, 0, 0, &CurKey) == ERROR_SUCCESS)
			{
				// Get the record size first
				if (RegQueryValueEx(CurKey, lpszValueName, NULL, &dwType, (PBYTE)NULL, &dwDataSize) == ERROR_SUCCESS)
				{
					// Allocate memory block & Initialize to NULL
					lpszValue = new TCHAR[dwDataSize + 1];
					memset(lpszValue, TEXT('\0'), dwDataSize + 1);
					// Read the data value...
					if (RegQueryValueEx(CurKey, lpszValueName, NULL, &dwType, (PBYTE)(LPTSTR)lpszValue, &dwDataSize) == ERROR_SUCCESS)
					{
						//Return the default value
						RegCloseKey (CurKey);
						return lpszValue;						
					}
					else
					{
						//Return the default value
						RegCloseKey (CurKey);
						return (LPTSTR)pcDefault;
					}
				}
				else
				{
					//Return the default value
					RegCloseKey (CurKey);
					return (LPTSTR)pcDefault;
				}
			}
			else
			{
				//Return the default value
				RegCloseKey (CurKey);
				return (LPTSTR)pcDefault;
			}
		}
		else
			//Return the default value
			return (LPTSTR)pcDefault;
	}
	//Return the default value
	return (LPTSTR)pcDefault;

}


//-----------------------------------------------------------
//
//	DWORD
//
//-----------------------------------------------------------

BOOL SaveDWORD (HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, DWORD dwValue)
{
	//  PURPOSE:  
	//		- Save the data into registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Save the given data into the given key and value name.
	//  RETURN VALUE:
	//      - 0		:: Fail
	//		  1		:: Pass

	//Registry Key Handle
	HKEY	CurKey;
	DWORD	dwDisposition=0;

	BOOL	fRes=false;

	// Sanity check
	if (lpszSubkey != NULL && lpszValueName != NULL)
	{
		// Sanity check
		if (_tcslen(lpszSubkey) > 0 && _tcslen(lpszValueName) > 0)
		{
			// OPen registry
			if (RegOpenKeyEx(lpszKey, lpszSubkey, 0, 0, &CurKey) == ERROR_SUCCESS)
			{
				// Update value
				if (RegSetValueEx(CurKey, lpszValueName, 0, REG_DWORD, (PBYTE)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS)
					fRes = true;
			}
			else
			{
				// Create new key
				if (RegCreateKeyEx(lpszKey, lpszSubkey, 0, 0, 0, 0, NULL, &CurKey, &dwDisposition) == ERROR_SUCCESS)
				{
					// Update value
					if (RegSetValueEx(CurKey, lpszValueName, 0, REG_DWORD, (PBYTE)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS)
						fRes = true;
				}
			}
		}
	}
	// Close the register
	RegCloseKey (CurKey);
	// Set the return value
	return fRes;
}


DWORD ReadDWORD	(HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, DWORD dwDefault)
{
	//  PURPOSE:  
	//		- Read the data from registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Write the given data into the given key and value name.
	//  RETURN VALUE:
	//      - Value

	// Registry Key Handle
	HKEY	CurKey;
	DWORD	dwType = REG_DWORD;
	DWORD	dwDataSize = sizeof(DWORD);
	DWORD	dwValue = 0;

	// Sanity check
	if (lpszSubkey != NULL && lpszValueName != NULL)
	{
		// Sanity check
		if (_tcslen(lpszSubkey) > 0 && _tcslen(lpszValueName) > 0)
		{
			// Sanity check
			if (RegOpenKeyEx(lpszKey, lpszSubkey, 0, 0, &CurKey) == ERROR_SUCCESS)
			{
				// Read the data value...
				if (RegQueryValueEx(CurKey, lpszValueName, NULL, &dwType, (PBYTE)&dwValue, &dwDataSize) == ERROR_SUCCESS)
				{
					//Return the default value
					RegCloseKey (CurKey);
					return dwValue;
				}
				else
				{
					//Return the default value
					RegCloseKey (CurKey);
					return dwDefault;
				}
			}
			else
			{
				//Return the default value
				RegCloseKey (CurKey);
				return dwDefault;
			}
		}
		else
			//Return the default value
			return dwDefault;
	}
	//Return the default value
	return dwDefault;
}

//-----------------------------------------------------------
//
//	BINARY
//
//-----------------------------------------------------------

BOOL SaveBinary (HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, DWORD dwValue)
{
	//  PURPOSE:  
	//		- Save the data into registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Save the given data into the given key and value name.
	//  RETURN VALUE:
	//      - 0		:: Fail
	//		  1		:: Pass


	return false;
}


DWORD ReadBinary (HKEY lpszKey, LPCTSTR lpszSubkey, LPCTSTR lpszValueName, DWORD dwDefault)
{
	//  PURPOSE:  
	//		- Read the data from registry.
	//  PARAMETERS:
	//		- NIL
	//  OPERATION:
	//		- Open the registry at the given location.
	//		- Write the given data into the given key and value name.
	//  RETURN VALUE:
	//      - Value

	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)


Written By
Software Developer
Australia Australia
Passion to be a software architect and solution researcher in enterprise solutions by simplify and unify the existing complex manual paper works into an automated environment friendly, comprehensive and dynamic workflow process system.

Comments and Discussions