Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using C++ to work with Windows reg

Status
Not open for further replies.

labnotes

Technical User
Sep 1, 2003
33
CA
I am trying to look at the registry on a WINNT machine. I have
the microsoft SDK loaded and am using it's lib and header files but can't seem to get the information I am expecting.
Here's my simple code that I expect should provide the same response as from a dos prompt "reg query HKLM\software\microsoft"

#include <iostream>
#include <stdlib.h>
#include <WINReg.H>
#include <Windows.h>

#include "main.h"

using namespace std;

HKEY usersKey;

char zsBuffer[1048];
signed long int *i;
DWORD j;
int len;

int main(int argc, char *argv[])
{

LONG cb = len;
j = RegQueryValue(HKEY_LOCAL_MACHINE, ("SOFTWARE\\Microsoft") ,zsBuffer,&cb);

cout << "buffer-" << zsBuffer << "-buffer " << (DWORD) j << " j" << endl;

system("PAUSE");

return 0;
}

the response I get is

buffer--buffer 0 j
Press any key to continue . . .

The 0 indicates The function completed successfully. (I believe)

Any help would be appreciated
 
If you query a value of a registry key (not of a registry variable) you get the default value of it. Take a look in registry at HKLM\SOFTWARE\Microsoft default value marked as "(Default)". I'm 100% sure you will see there "(value not set)"

Ion Filipski
1c.bmp
 
1. Use RegQueryValueEx(0 instead of RegQueryValue() - MS recommendation...
2. Use RegQueryInfoKey(), RegEnimKeyEx(0 et al funcs to inspect registry keys...
3. See MSDN - there are a lot of info&samples about reg keys access (search any of these names)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top