?
Solved

Reading registry in VC++ 6.0 ??

Posted on 2003-02-25
8
Medium Priority
?
2,828 Views
Last Modified: 2012-06-21
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
Comment
Question by:raghavphil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:Fallen_Knight
ID: 8023193
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
 
LVL 3

Accepted Solution

by:
cmaryus earned 100 total points
ID: 8023203
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
 

Expert Comment

by:alexanderthegreat
ID: 8024686
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.

 
LVL 3

Expert Comment

by:cmaryus
ID: 8024734
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
 

Expert Comment

by:alexanderthegreat
ID: 8024956
Thanks, but why do you use it that way if it has the same result?
0
 
LVL 3

Expert Comment

by:cmaryus
ID: 8025013
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
 

Expert Comment

by:alexanderthegreat
ID: 8025046
THanks for ya answer.
0
 

Author Comment

by:raghavphil
ID: 8031055
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question