网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > VC++ > 正文
关于注册表的源程序
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/15
下载{$ArticleTitle}原创论文样式

// Registry.cpp

#include "stdafx.h"
#include "Registry.h"

CRegistry::CRegistry()
{

m_hKey = NULL;
Open( _hKey, m_strUseKey );

}

CRegistry::CRegistry( HKEY hKey, const char *lpszSubKey )
{

m_hKey = NULL;
Open( hKey, lpszSubKey );

}

CRegistry::~CRegistry()
{

Close();

}

BOOL CRegistry::Open( HKEY hKey, const char *lpszSubKey )
{

Close();

if( ::RegOpenKeyEx( hKey, lpszSubKey, 0, KEY_ALL_ACCESS, &m_hKey ) != ERROR_SUCCESS ){
m_hKey = NULL;
m_dwLastError = GetLastError();
return( FALSE );
}

return( TRUE );

}

BOOL CRegistry::Close( void )
{
BOOL bRet = TRUE;

if( m_hKey == NULL )
return( FALSE );

bRet = ( ::RegCloseKey( m_hKey ) == ERROR_SUCCESS );
m_hKey = NULL;

return( bRet );

}

BOOL CRegistry::IsOpen( void )
{

return( m_hKey != NULL );

}

BOOL CRegistry::Read( const char *lpszValueName, LPVOID lpReturnBuffer, int nSize )
{

if( m_hKey == NULL )
return( FALSE );

DWORD dwSize = (DWORD) nSize;
BOOL bRet = ( ::RegQueryValueEx( m_hKey, lpszValueName, NULL, NULL, (unsigned char *) lpReturnBuffer, &dwSize ) == ERROR_SUCCESS );

m_dwLastError = GetLastError();

return( bRet );

}

BOOL CRegistry::ReadDWORD( const char *lpszValueName, DWORD *pdwData, DWORD *pdwLastError )
{

if( m_hKey == NULL )
return( FALSE );

BOOL bRet = Read( lpszValueName, pdwData, sizeof( DWORD ) );

if( pdwLastError != NULL )
*pdwLastError = m_dwLastError;

return( bRet );

}

BOOL CRegistry::ReadString( const char *lpszValueName, LPVOID lpReturnBuffer, int nSize, DWORD *pdwLastError )
{

if( m_hKey == NULL )
return( FALSE );

char *lpWork = (char *) lpReturnBuffer;
lpWork[0] = 0;
BOOL bRet = Read( lpszValueName, lpReturnBuffer, nSize );

if( pdwLastError != NULL )
*pdwLastError = m_dwLastError;

return( bRet );

}

char **CRegistry::ReadMultipleStrings( const char *lpszValueName, DWORD *pdwLastError )
{
char szEntireString[2500];

if( !ReadString( lpszValueName, szEntireString, 2500, pdwLastError ) )
return( NULL );

if( szEntireString[0] == 0 )
return( NULL );

int nCount = 0;
if( szEntireString[strlen(szEntireString)-1] != '';'' )
nCount = 1;
char *pPointer = szEntireString;
do{
pPointer = strstr( pPointer, ";" );
if( pPointer != NULL ){
nCount++;
pPointer++;
}
} while( pPointer != NULL );

int i = 0;
char *pEnd;
char **pList = (char **) new char [(nCount+3)*sizeof(char *)];
if( pList == NULL )
return( NULL );
memset( pList, 0, ( nCount + 3 ) * sizeof(char *) );

pPointer = szEntireString;
do{

pEnd = strstr( pPointer, ";" );
int nSize = strlen( pPointer );
if( pEnd != NULL )
nSize = pEnd - pPointer;

pList[i] = new char [nSize+3];
if( pList[i] != NULL ){
memset( pList[i], 0, nSize + 3 );
memcpy( pList[i], pPointer, nSize );
}
else pEnd = NULL;

pPointer = pEnd;
if( pPointer != NULL )
pPointer++;

i++;

} while( pPointer != NULL && pPointer[0] != 0 );

return( pList );

}

void CRegistry::DeleteList( char **pList )
{

if( pList == NULL )
return;

int i = 0;
while( pList[i] != NULL ){
delete pList[i];
i++;
}
delete pList;

}

BOOL CRegi
  • 下一篇资讯: 使用目录内容建立菜单
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号