Okay, so I've been looking at this for quite some time. I think I know what the problem is, but my C++ skills are sad a best due to stuff like Java, C# and VB. So, I'm trying to pull information from the registry, and I have no problem getting it to work. I can pull REG_SZ values just fine. I can output them and everything. Now, I'm trying to get REG_DWORDs to work, but am having issues. When I have it look at something that has a DWORD value of like 546258943, the program spits out something like " ?Å ╪·"☺t·"" Unfortunately, this is not my intended output. So, the way I see it, I've got this char buffer that I'm filling with this numerical data, which it's interpreting as a character array what it outputs it. So, my dilemma is to get it not to do that.

#include <windows.h>
#include <iostream>
using namespace std;

int main () {
    HKEY keyHandle;
    char rgValue [1024];

	LPCTSTR regPath = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
    LPCTSTR regReq = "FeatureSet";
 
    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);

    std::cout << "Returned: -->" << rgValue << "<-- (at least I think so) \n\n";
    system("Pause");
}

You shouldn't just output rgValue, it is binary data unless Type has a value of REG_EXPAND_SZ, REG_MULTI_SZ, REG_SZ.

If the value in the registry is really a DWORD then Type should be REG_DWORD and size1 should be 4 on exit. In that case something (non-portable) like DWORD dwValue = *((DWORD*)rgValue); should do the trick. Alternatively just pass a pointer to a DWORD into RegQueryValueEx in the first place if you are sure of the type the key holds.

RTFM: RegQueryValueEx

commented: Yes! +0

“He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever”

Okay, that made a lot more sense. I appreciate your help!

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.