Registry API functions

I want to write a simple console application program that will read a registry key.  I want to use the RegOpenKeyEx, RegQueryKeyEx, and RegCloseKey registry API functions.  I am having trouble figuring out how to get started (what files to include and such).  I started a new console application project (in VC++ 6.0) and chose to create a simple "Hello World" program.  From there, I tried to include <winreg.h>, but when I tried to compile it, the compiler reported finding an error in winreg.h (something like it didn't find a semicolon where it thought there should be one).  I don't expect errors to be in standard header files that come with VC++, so I am assuming that I am doing something wrong.  Can someone explain the right way to include header files that will enable me to use registry functions.  Simple sample code would be great.
tdiamondAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexVirochovskyCommented:
Next is my code for make it
int Test(void)
{
  int bStop = 0;
      // skip registry key opening sequence for clarity
  const INT nSIZE = 4096; //maximum(real 8)
  const DWORD dwLen = 8;
  const char *lpszPathName = "SOFTWARE\\COMPANY\\MYCOMPANY";
  const char *pszValueName = "Param01";

  HKEY hKey,hBaseKey = HKEY_LOCAL_MACHINE;
  DWORD dwType;
  DWORD dwData  = nSIZE;
  char* bData   = (char *)::calloc(nSIZE, sizeof(char));
  struct date dDate;
  LONG retValue;

                        //open key
  retValue = ::RegOpenKeyEx(hBaseKey, lpszPathName,
                   NULL, KEY_ALL_ACCESS,&hKey);
  if (retValue != ERROR_SUCCESS)//no such : 1-st time
    {                           //create key
       uint32 disposition;
       retValue = ::RegCreateKeyEx(hBaseKey, lpszPathName, 0, ""/*class*/,
                REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
                0/*SecurityAttributes*/, &hKey,
                &disposition);
       if (retValue == ERROR_SUCCESS)//must be!
       {
          //you code for form bData
                        //save data
         ::RegSetValueEx(hKey, pszValueName, 0, REG_BINARY,
                    (LPBYTE)bData, dwLen);
         ::RegCloseKey(hKey); //close key
       }
    }
  else            //exist, read data
    {
      retValue = ::RegQueryValueEx(hKey, pszValueName,
                    NULL, &dwType,(LPBYTE)bData, &dwData);

       if (retValue == ERROR_SUCCESS && REG_BINARY == dwType)
       {
         if (Empty(bData))      //no data?
           {
             //you code for form bData
                  // Save
            ::RegSetValueEx(hKey, pszValueName, 0, REG_BINARY,
                    (LPBYTE)bData, dwLen);
           }
         else  //test data
           {
           }

       }
      ::RegCloseKey(hKey);            //close key
    }
  if (bData)
    free (bData);
  return bStop;
}
Alex
0
chensuCommented:
#include <windows.h>

instead of

#include <winreg.h>
0
tdiamondAuthor Commented:
AlexVirochovsky, thanks for the code, although you forgot to tell me what header files to include so your code would work on my machine.  You can thank Chensu for his comment.

Thanks Chensu...
0
tdiamondAuthor Commented:
AlexVirochovsky - I made a mistake and rejected your answer by mistake.  Answer it again and I will grade it.

Sorry again...
0
AlexVirochovskyCommented:
Ok, thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.