1

I am Creating the Registry Key using following code:

 LPCTSTR lpNDS= TEXT("SOFTWARE\\myKEY"); if(OK==ERROR_SUCCESS) { MessageBox ( NULL, "Success", _T("SimpleShlExt"), MB_ICONINFORMATION ); } else { MessageBox ( NULL, "Failed" , _T("SimpleShlExt"), MB_ICONINFORMATION ); } LONG openRes = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpNDS, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hRegKey, NULL); if (openRes!=ERROR_SUCCESS) MessageBox ( NULL, "Registry Createion Failed", _T("SimpleShlExt"), MB_ICONINFORMATION ); 

Now I am writing up to the Key using:

CSimpleShlExt::WriteToRegistry(LPSTR lpRegKeyVal) { LONG setRes = RegSetValueEx (hRegKey, "NDS", 0, REG_SZ, (LPBYTE)lpRegKeyVal, strlen(lpRegKeyVal)+1); CloseRegistryKey(); } 

Now I am trying read the registry key value that I have created using WriteToRegistry function. I have tried with

RegOpenKeyEx(hRegKey,lpNDS,0,KEY_QUERY_VALUE,&hRegKey); 

But this is failing.

Which function shall I use to read the value contained inside the key?

2 Answers 2

1

You can try something like :

TCHAR szValue[TEMP_STR_SIZE] = {0}; DWORD dwStorageSize = TEMP_STR_SIZE; LPBYTE lpStorage = reinterpret_cast<LPBYTE>(szValue); // In case of registry value retrieval failure if (ERROR_SUCCESS != RegQueryValueEx(hRegKey, _T("NDS"), 0, 0, lpStorage, &dwStorageSize)) { // Prompt error } 

Edit:
Just noticed there are no subkey, changed my sample code

Sign up to request clarification or add additional context in comments.

2 Comments

Now How will I get the Value of the RegistryKey, In My Case , I am writing some value to NDS. *lpStorage is an Integer. Sorry for being so simple but I am just new to this
if (ERROR_SUCCESS == RegQueryValueEx(hRegKey, _T("NDS"), 0, 0, (BYTE*)szValue, &dwBufSize)) { MessageBox ( NULL, szValue, _T("Value"), MB_ICONINFORMATION ); }
1

Which function shall I use to read the value contained inside the key?

Try RegQueryValue and/or RegEnumValue. Read the documentation to see which one suits your needs the best.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.