RegQueryValueEx and ÌÌÌÌÌÌÌÌÌÌÌÌÌ !!!!
Does anyone know why my code gives me "ÌÌÌÌÌÌÌÌÌÌÌÌÌ"

Here's the code.

HKEY keyHandle;
char rgValue [1024];

LPCTSTR regPath = "Volatile Environment";
LPCTSTR regReq = "USERDNSDOMAIN";

DWORD size1;
DWORD Type;
if( RegOpenKeyEx(HKEY_CURRENT_USER, regPath,0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
{
RegQueryValueEx( keyHandle, regReq, NULL, &Type, (LPBYTE)rgValue,&size1);
}
RegCloseKey(keyHandle);

variable size1 must be set to the length of the input buffer, 1024 in your example. you might also initialize rgValue to 0

char rgValue [1024] = {0};

variable size1 must be set to the length of the input buffer, 1024 in your example. you might also initialize rgValue to 0

char rgValue [1024] = {0};

Any idea how to do the length of the input buffer? I'm really green with this.

Any idea how to do the length of the input buffer? I'm really green with this.

length was the wrong word to use. size is what it wants, in your case it will be 1024.

DWORD size1 = sizeof(rgValue);

length was the wrong word to use. size is what it wants, in your case it will be 1024.

DWORD size1 = sizeof(rgValue);

Hey, that seemed to work well. It nulled that nasty set of characters. But can I ask you one more question. I'm now trying to access values from HKEY_LOCAL_MACHINE but the LPCTSRT seems to be removing the '\' in my assignment statement for regPath . Can you help?

LPCTSTR regPath = "SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName";
LPCTSTR regReq = "ComputerName";
 
DWORD size1 = sizeof(rgValue);
DWORD Type;
 
if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, regPath,0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
{
RegQueryValueEx( keyHandle, regReq, NULL, &Type, (LPBYTE)rgValue,&size1); 
} 
RegCloseKey(keyHandle);
tempString = rgValue;

The '\' character is called an escape character in c and c++ languages. If you want a literal '\' you have to use two of them, like this:

LPCTSTR regPath = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";

The '\' character is called an escape character in c and c++ languages. If you want a literal '\' you have to use two of them, like this:

LPCTSTR regPath = "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";

Ancient Dragon, that worked out perfectly!!! I can't thank you enough for all your help! Are you around the forum much if I have any more questions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.