How to write registry?
-
I am building a project.I want to write something to registry to save some informatiom.
-
I am building a project.I want to write something to registry to save some informatiom.
Who can give me a sample or a demo?
-
Who can give me a sample or a demo?
Use RegOpenKey, RegQueryValue, RegCloseKey. You can look for sample code in MSDN, or you can search Google for a whole lot of sample code You might also find some code on CP "It was when I found out I could make mistakes that I knew I was on to something." -Ornette Coleman
-
Who can give me a sample or a demo?
Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards
-
Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards
Thank you very much!!
-
Here are some code snippets, which you may use : ////////////////////////////////////////////////////// CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault ) { CString csResult = csDefault; CRegKey* pRK = new CRegKey(); LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString); if(lRegOpen == ERROR_SUCCESS) { char cValue[1000]; memset( cValue, 0, sizeof( cValue ) ); DWORD dwSize = sizeof( cValue ); LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize ); if(lRegQuery == ERROR_SUCCESS) csResult = cValue; } delete pRK; pRK = NULL; return( csResult ); } ////////////////////////////////////////////////////// BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue ) { BOOL bResult = FALSE; CRegKey* pRK = new CRegKey(); LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField ); if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE; delete pRK; pRK = NULL; return( bResult ); } I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it. Best regards
csc wrote: I think there are a lot of complete classes here at codeguru. Codeguru? Don't you mean CodeProject? :)