• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2829
  • Last Modified:

Reading registry in VC++ 6.0 ??

Hi all,
I'm new to VC++ and i've stuck with a problem.
How can we read registry values & strings in VC++.
which class should we access.
Pls help me out.

bye
raghavphil
0
raghavphil
Asked:
raghavphil
1 Solution
 
Fallen_KnightCommented:
see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_functions.asp

the basic idea is you open a handle to the key with
RegOpenKey()

you can then query values with:
RegQueryValueEx()

or go thru all values in the key with:
RegEnumValue()

and the when done you close the key with
RegCLoseKey()

if you still need help after reading the docs just ask
0
 
cmaryusCommented:
You can use the Windows API's. Here is a small example:

#include <windows.h>

int main()
{
     LONG result;
     HKEY hKey;
     char szProductDir[100];
     DWORD dwBufLen = sizeof(szProductDir);

     // open a registry key for query (reading it's value) and set (writing a new value)
     result = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
        "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
        0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey );

     if(ERROR_SUCCESS != result)
     {
          return 1;
     }

     // now in hKey you got a handler to that key
     // read a value...
     result = RegQueryValueEx( hKey, "ProductDir", NULL, NULL,
        (LPBYTE) szProductDir, &dwBufLen);

     // now in dwBufLen you have the size of the string read form registry

     if(ERROR_SUCCESS != result)
     {
          return 1;
     }


     // write a value
     char szBuffer[] = "New value";
     result = RegSetValueEx(hKey, "ProductDir", 0, REG_SZ, (BYTE *)szBuffer, strlen(szBuffer));
     if(ERROR_SUCCESS != result)
     {
          return 1;
     }

     // close the key...
     RegCloseKey( hKey );

     return 0;
}
0
 
alexanderthegreatCommented:
a little question,
what is the differents between LONG and long or DOUBLE or double and what does the class FILE do,
i have no documentation with my compiler so please explain, thx a lot.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
cmaryusCommented:
In Winnt.h you wil find:
typedef char CHAR;
typedef short SHORT;
typedef long LONG;

In Wtypes.h
typedef double DOUBLE;

So ..it's the same...
0
 
alexanderthegreatCommented:
Thanks, but why do you use it that way if it has the same result?
0
 
cmaryusCommented:
These are the windows data types. Of course, behind they're still the same types from C, but that's the windows interface. So it's your choice: either use the C types either use the types provided by the windows interface.
0
 
alexanderthegreatCommented:
THanks for ya answer.
0
 
raghavphilAuthor Commented:
ooof !
cmaryus..... thanx a lot.
This was the kind of answer i was looking for.
it told me many things abt the registry..... that too with a nice working example.
thank you.
bye
raghav
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now