class LboxReg

  オブジェクトの作成と削除および使用例



  
LboxDlg *Dlg;
LboxReg *Reg;
LboxString Buff;

LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message ) {
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );

			Reg = new LboxReg(
				HKEY_LOCAL_MACHINE,
				"SOFTWARE\\"
				"Microsoft\\"
				"VisualStudio\\"
				"6.0\\"
				"Setup\\"
				"Microsoft Visual C++"
			);

			Reg->GetStrValue( "ProductDir", &Buff );
			Dlg->EditSetText( IDC_EDIT1, &Buff );

			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Reg;
				delete Dlg;
			}
			break;
	}
	return FALSE;
}
  



  コンストラクタ



  
// *********************************************************
// 標準コンストラクタ
// *********************************************************
LboxReg::LboxReg()
{
	LboxReg::hKey = NULL;
}

// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxReg::LboxReg(HKEY hRoot, LPCTSTR lpSubKey)
{
	LONG	nRet;

	nRet = RegOpenKeyEx(
		hRoot,
		lpSubKey,
		0,
		KEY_ALL_ACCESS,
		&(LboxReg::hKey)
	);
	if ( nRet != ERROR_SUCCESS ) {
		LboxReg::hKey = NULL;
	}

}

// *********************************************************
// デストラクタ
// *********************************************************
LboxReg::~LboxReg()
{
	if ( LboxReg::hKey != NULL ) {
		RegCloseKey( LboxReg::hKey );
	}
}
  



  GetStrValue

  
// *********************************************************
// 文字列値の取得
// *********************************************************
BOOL LboxReg::GetStrValue(LPCTSTR lpEntry, LboxString &LString)
{
	return(LboxReg::GetStrValue(lpEntry, &LString));
}
BOOL LboxReg::GetStrValue(LPCTSTR lpEntry, LboxString *LString)
{
	DWORD nType,nSize;
	LONG nRet;

	nSize = LString->nLboxString;

	nRet = RegQueryValueEx(
		LboxReg::hKey,
		lpEntry,
		NULL,
		&nType,
		(LPBYTE)(LString->szLboxString),
		&nSize
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		if ( nRet == ERROR_MORE_DATA ) {
			LString->Resize( nSize );
			nRet = RegQueryValueEx(
				LboxReg::hKey,
				lpEntry,
				NULL,
				&nType,
				(LPBYTE)(LString->szLboxString),
				&nSize
			);
			if ( nRet == ERROR_SUCCESS ) {
				return TRUE;
			}
			else {
				return FALSE;
			}
		}
		else {
			return FALSE;
		}
	}
}
  



  SetStrValue

  
// *********************************************************
// 文字列値の登録
// *********************************************************
BOOL LboxReg::SetStrValue(LPCTSTR lpEntry, LboxString &LString)
{
	return LboxReg::SetStrValue( lpEntry, LString.szLboxString );
}
BOOL LboxReg::SetStrValue(LPCTSTR lpEntry, LboxString *LString)
{
	return LboxReg::SetStrValue( lpEntry, LString->szLboxString );
}
BOOL LboxReg::SetStrValue(LPCTSTR lpEntry, LPTSTR lpValue)
{
	LONG nRet;

	nRet =  RegSetValueEx(
		LboxReg::hKey,
		lpEntry,
		0,
		REG_SZ,
		(const unsigned char *)lpValue,
		lstrlen(lpValue)+1
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		return FALSE;
	}
}
  



  GetDwordValue

  
// *********************************************************
// DWORD 値の取得
// *********************************************************
BOOL LboxReg::GetDwordValue(LPCTSTR lpEntry, DWORD &Value )
{
	return(LboxReg::GetDwordValue(lpEntry, &Value ));
}
BOOL LboxReg::GetDwordValue(LPCTSTR lpEntry, DWORD *Value )
{
	DWORD nType,nSize;
	LONG nRet;

	nSize = 4;

	nRet = RegQueryValueEx(
		LboxReg::hKey,
		lpEntry,
		NULL,
		&nType,
		(LPBYTE)Value,
		(unsigned long *)(&nSize)
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		return FALSE;
	}
}
  



  SetDwordValue

  
// *********************************************************
// DWORDの登録
// *********************************************************
BOOL LboxReg::SetDwordValue(LPCTSTR lpEntry, DWORD dwValue )
{
	LONG nRet;
	long nLen;

	nLen = 4;

	nRet =  RegSetValueEx(
		LboxReg::hKey,
		lpEntry,
		0,
		REG_DWORD,
		(const unsigned char *)&dwValue,
		nLen
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		return FALSE;
	}
}
  



  GetBinValue

  
// *********************************************************
// バイナリ値の取得
// *********************************************************
BOOL LboxReg::GetBinValue(LPCTSTR lpEntry, void *Value, int nSize )
{
	DWORD nType;
	LONG nRet;

	nRet = RegQueryValueEx(
		LboxReg::hKey,
		lpEntry,
		NULL,
		&nType,
		(LPBYTE)Value,
		(unsigned long *)(&nSize)
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		return FALSE;
	}
}
  



  SetBinValue

  
// *********************************************************
// バイナリの登録
// *********************************************************
BOOL LboxReg::SetBinValue(LPCTSTR lpEntry, void *Value, int nLen )
{
	LONG nRet;

	nRet =  RegSetValueEx(
		LboxReg::hKey,
		lpEntry,
		0,
		REG_BINARY,
		(const unsigned char *)Value,
		nLen
	);

	if ( nRet == ERROR_SUCCESS ) {
		return TRUE;
	}
	else {
		return FALSE;
	}
}
  



  Create

  
// *********************************************************
// レジストリキーの作成
// *********************************************************
BOOL LboxReg::Create( HKEY hRoot, LPCTSTR lpSubKey )
{
	LONG nRet;
	HKEY hNew;
	DWORD dwDisposition;

	nRet = RegCreateKeyEx(
		hRoot,
		lpSubKey,
		0,
		NULL,
		REG_OPTION_NON_VOLATILE,
		KEY_ALL_ACCESS,
		NULL,
		&hNew,
		&dwDisposition
	);

	if ( nRet == ERROR_SUCCESS ) {
		if ( dwDisposition == REG_OPENED_EXISTING_KEY ) {
			RegCloseKey( hNew );
		}
		else {
			RegCloseKey( this->hKey );
			this->hKey = hNew;
		}
		return true;
	}
	return false;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ