大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 关于注册表的源程序

关于注册表的源程序

时间: 2021-07-31 作者:daque

// 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 cregistry::writedword( const char *lpszvaluename, dword dwdata, dword *pdwlasterror ) { if( m_hkey == null ) return( false ); m_nsize = sizeof( dword ); bool bret = write( lpszvaluename, &dwdata, reg_dword, sizeof( dword ) ); if( pdwlasterror != null ) *pdwlasterror = m_dwlasterror; return( bret ); } bool cregistry::writestring( const char *lpszvaluename, lpvoid lpdata, dword *pdwlasterror ) { if( m_hkey == null ) return( false ); m_nsize = 2000; bool bret = write( lpszvaluename, lpdata, reg_sz, (dword) strlen( (const char *) lpdata ) + 1 ); if( pdwlasterror != null ) *pdwlasterror = m_dwlasterror; return( bret ); } bool cregistry::write( const char *lpszvaluename, lpvoid lpdata, dword dwtype, int nsize ) { if( m_hkey == null ) return( false ); dword dwsize = (dword) m_nsize; bool bret = ( ::regsetvalueex( m_hkey, lpszvaluename, 0, dwtype, (unsigned char *) lpdata, nsize ) == error_success ); m_dwlasterror = getlasterror(); return( bret ); } bool cregistry::createkey( hkey hkey, const char *lpszsubkey, const char *lpszclass ) { hkey hopenedkey; dword dwdisposition; dword dwlasterror; bool bret = ( ::regcreatekeyex( hkey, lpszsubkey, 0, (char *) lpszclass, reg_option_non_volatile, key_all_access, null, &hopenedkey, &dwdisposition ) == error_success ); if( bret ) ::regclosekey( hopenedkey ); dwlasterror = getlasterror(); return( bret ); } bool cregistry::deletekey( hkey hkey, const char *lpszsubkey ) { bool bret; dword dwlasterror; bret = ( ::regdeletekey( hkey, lpszsubkey ) == error_success ); dwlasterror = getlasterror(); return( bret ); }

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.