Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
All I'm attempting to do, is something simple; like reading an item from the registry. Now hold on there, please!.
For example: Given an registry address(\SOFTWARE\Acer\Hermes) under the domain of (HKEY_CURRENT_USER),
I've attempted to read/get an item-info under that registry address for an item. I can open the registry address ok, but to read an item, that
has been a heart wrenching experience. I've been using GetRegValue, RegQueryValueEx, and not RegenumValue - and then shuttling back and forth
between them. The end results from all these calls have been an error code of 2(two). And yes, I've been trying to follow the said rules.
And it's been a very frustrating process. From what definitions I could find out about error code two(2), MS gives it the meaning
of "FILE_NOT_FOUND". File not found???? I can open the registry with the Registry functions like: RegOpenKeyExA or RegCreateKeyExA
and have done alright. I will include the "C" code that I use. Yes, I've left past work attempts in my code, indicating different past failed attempts.
Please pardon my many frustrations. Could anyone put me back on the correct road and help get this working correctly. But Thanks in advance.
And get this 'get function's end results to leave me an error-code of zero(0)...
And Again, A Big Thanks!.
(Member 15028314)... Oh, this is not a school assignment.

What I have tried:

C++
///GetRegStrValue 
int GetRegStrValue(char * keyaddress, char * keypeople, char * retsname, int idlocate) {
////	Dim retval$, hSubKey As Long, dwType As Long, sz As Long

#define SBUFFER 8192
    char value[255];
    DWORD BufferSize = SBUFFER;
    int iretval, rv, iwhloc = 2345, iwhch = 1;
    long lrv, rv1,irv;
    char defaultvalue[12];
	HKEY hSubKey = NULL;
    char buffer[100]; 
	DWORD DWbufsize;
    strcpy(defaultvalue, "XXXXX");
////    strcpy(buffer, "\0");
#define MAX_VER_LEN 255 
    DWORD data_len = MAX_VER_LEN;
    char new_data[MAX_VER_LEN];

///    REGSAM flagz = KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS; 
    iretval = 0;
    lrv = RegOpenKeyExA(HKEY_CURRENT_USER, keyaddress, 0, KEY_READ | KEY_WRITE | KEY_WOW64_64KEY, &hSubKey);
    if (lrv != ERROR_SUCCESS) {
        lrv = RegCreateAddSetString(keyaddress, keypeople, defaultvalue, iwhch, iwhloc);
    }
	if (lrv == ERROR_SUCCESS) {
        RegCloseKey(hSubKey);   ////  somewhere in this area, an exception unhandler was thrown...
        //if (isWin64Bit()) flagz |= KEY_WOW64_64KEY;
        //else flagz |= KEY_WOW64_32KEY;
        lrv = RegOpenKeyExA(HKEY_CURRENT_USER, keyaddress, 0, KEY_READ | KEY_WRITE, &hSubKey);
        strcpy(buffer, "\0");
        strcpy(new_data, "\0");
        ///  OK TO HERE...                  //// | RRF_SUBKEY_WOW6464KEY
///------------------------------------------

        lrv = RegGetValue(hSubKey, NULL, (LPCWSTR)keypeople, RRF_RT_REG_SZ , NULL, (PVOID)&new_data, &data_len);
//// this above sentence is giving me major grief!!    

       //rv1 = RegQueryValueEx(hSubKey, (LPCWSTR)keypeople, NULL, &type, 0, &nbytes);
        ///// 
        ///results = (char*)malloc(nbytes + 1);
        ///lrv = RegQueryValueEx( hSubKey,  (LPCWSTR)keypeople, NULL, &type, (BYTE*)buffer, &DWbufsize );

		if (lrv == ERROR_SUCCESS) {    //// Exception Unhandled thrown approx here.. 
			RegCloseKey(hSubKey);   ////  somewhere in this area, an exception unhandler was thrown...
			iretval = 1;
///			strcpy(retsname, results);
            ///            printf(" *K IN*  GetRegStrValue, %d,   <%s>   \n", strlen(results), results);
            printf(" ***  GetRegStrValue, %d,   <%s>   \n", strlen( (char *)buffer), buffer);
        }
		else {   
			iretval = -2;
			rv = ReportErrorString(lrv, idlocate);
		}   ///  <error-type> hSubKey /// exception Unhandled has been thrown here.   located?? at "return(iretval);  
	}
	else { 
		iretval = -3;
		rv = ReportErrorString(lrv,idlocate);
	}
	return(iretval);
 }
/////////------------------------------------
Posted
Updated 30-Nov-22 12:43pm
Comments
merano99 30-Nov-22 17:51pm    
I cannot find the function RegCreateAddSetString(). Google is also at a loss.
Rick York 30-Nov-22 18:32pm    
Your function is named a bit strangely. It is called GetRegStrValue but it calls the function RegCreateAddSetString. To me, this is a side effect that I would not expect from a function with that name.
Richard MacCutchan 1-Dec-22 4:34am    
It looks like you have a number of function calls that are not part of the Win32 library, RegCreateAddSetString for example. But it is also not clear exactly what you are trying to do, or what the problem is with your code. In my experience of these functions, reading keys, subkeys and values is quite straightforward, assuming you have the correct permissions to access the data.
Member 15028314 1-Dec-22 13:08pm    
The function: RegCreateAddSetString, is a user built function. This function creates the item and fills it with a value.

1 solution

Some functions do not seem to be defined. However, the following works for me:
C
TCHAR* lpSubKey = _T("SOFTWARE\\Logitech");
HKEY hSubKey = NULL;

LSTATUS lrv = RegOpenKeyExW(HKEY_CURRENT_USER, lpSubKey, 0, KEY_READ | KEY_WRITE | KEY_WOW64_64KEY, &hSubKey);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900