Reading the windows registry

Discussion in 'C++' started by Harbinger of Doom, Jul 1, 2003.

  1. Hello,

    I'm currently working on a program that has to read values from the windows
    registry.
    I use the functions "RegOpenKeyEx", "RegCloseKey" and "RegQueryValueEx" for
    that.
    If I can read the manual correctly (which I hope I can) I have to include
    windows.h, winnt.h and winreg.h

    The constructor of one of my classes looks like this:

    NodeListReader::NodeListReader(__int8 buffer)
    {
    HKEY *ptr1, *ptr2, *ptr3;
    *sizeOfBuffer = 2081;

    this->buffer = &buffer;

    long temp = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software", 0,KEY_READ, ptr1);

    temp = RegOpenKeyEx(*ptr1,"JavaSoft", 0,KEY_READ, *ptr2);

    temp = RegOpenKeyEx(*ptr2,"Java Development Kit", 0,KEY_READ, *ptr3);

    temp = RegQueryValueEx(*ptr3,"CurrentVersion", NULL, REG_SZ, this->buffer,
    *sizeOfBuffer);

    temp = RegCloseKey(*ptr3);

    temp = RegCloseKey(*ptr2);

    temp = RegCloseKey(*ptr1);
    }

    When I try to compile it, I get these errors:

    e:\nodelistcreator\nodelistreader.h(46) : error C2664: 'RegOpenKeyExA' :
    cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    Types pointed to are unrelated; conversion requires
    reinterpret_cast, C-style cast or function-style cast
    e:\nodelistcreator\nodelistreader.h(52) : error C2664: 'RegOpenKeyExA' :
    cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    Types pointed to are unrelated; conversion requires
    reinterpret_cast, C-style cast or function-style cast
    e:\nodelistcreator\nodelistreader.h(58) : error C2664: 'RegQueryValueExA' :
    cannot convert parameter 4 from 'const int' to 'unsigned long *'
    Conversion from integral type to pointer type requires
    reinterpret_cast, C-style cast or function-style cast

    I don't really know why I get these errors, since the RegOpenKeyEx and
    RegQueryValueEx functions expect a pointer to an open registry key.
    That's exactly what I give!

    Also, the errors state something about the functions "RegOpenKeyExA" and
    "RegQueryValueExA" (notice the 'A' in the end)
    The MSDN-library doesn't give any info on those routines. Are they really
    different routines that the ones without the 'A' in the end?
    or is that just something the compiler adds??

    thanks in advance!
    --
    Harbinger of Doom
    Harbinger of Doom, Jul 1, 2003
    #1
    1. Advertising

  2. "Victor Bazarov" <> schreef in bericht
    news:...
    > "Harbinger of Doom" <> wrote...
    > > I'm currently working on a program that has to read values from the

    > windows
    > > registry.
    > > I use the functions "RegOpenKeyEx", "RegCloseKey" and "RegQueryValueEx"

    > for
    > > that.
    > > If I can read the manual correctly (which I hope I can) I have to

    include
    > > windows.h, winnt.h and winreg.h
    > >
    > > The constructor of one of my classes looks like this:
    > >
    > > NodeListReader::NodeListReader(__int8 buffer)
    > > {
    > > HKEY *ptr1, *ptr2, *ptr3;
    > > *sizeOfBuffer = 2081;
    > >
    > > this->buffer = &buffer;
    > >
    > > long temp = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software", 0,KEY_READ,

    > ptr1);
    > >
    > > temp = RegOpenKeyEx(*ptr1,"JavaSoft", 0,KEY_READ, *ptr2);
    > >
    > > temp = RegOpenKeyEx(*ptr2,"Java Development Kit", 0,KEY_READ, *ptr3);
    > >
    > > temp = RegQueryValueEx(*ptr3,"CurrentVersion", NULL, REG_SZ,

    > this->buffer,
    > > *sizeOfBuffer);
    > >
    > > temp = RegCloseKey(*ptr3);
    > >
    > > temp = RegCloseKey(*ptr2);
    > >
    > > temp = RegCloseKey(*ptr1);
    > > }
    > >
    > > When I try to compile it, I get these errors:
    > >
    > > e:\nodelistcreator\nodelistreader.h(46) : error C2664: 'RegOpenKeyExA' :
    > > cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '

    >
    > The function apparently needs a pointer to a pointer to HKEY__ and
    > you're trying to pass a pointer to HKEY__ to it.
    >
    > > Types pointed to are unrelated; conversion requires
    > > reinterpret_cast, C-style cast or function-style cast
    > > e:\nodelistcreator\nodelistreader.h(52) : error C2664: 'RegOpenKeyExA' :
    > > cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    > > Types pointed to are unrelated; conversion requires
    > > reinterpret_cast, C-style cast or function-style cast
    > > e:\nodelistcreator\nodelistreader.h(58) : error C2664:

    'RegQueryValueExA'
    > :
    > > cannot convert parameter 4 from 'const int' to 'unsigned long *'
    > > Conversion from integral type to pointer type requires
    > > reinterpret_cast, C-style cast or function-style cast
    > >
    > > I don't really know why I get these errors, since the RegOpenKeyEx and
    > > RegQueryValueEx functions expect a pointer to an open registry key.
    > > That's exactly what I give!

    >
    > No, you don't. You give (*ptr2), which is 'HKEY' (or 'struct HKEY__*'
    > as it is known to the compiler), and the function expexts HKEY* (or
    > 'struct HKEY__**'), so you need to pass (ptr2). However, that won't
    > work because there is no HKEY behind the pointer. What you ought to
    > do was:
    >
    > HKEY key1, key2, key3;
    > ...
    > ... RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software",0,KEY_READ, &key1);
    >
    > and so on.
    >
    > >
    > > Also, the errors state something about the functions "RegOpenKeyExA" and
    > > "RegQueryValueExA" (notice the 'A' in the end)
    > > The MSDN-library doesn't give any info on those routines. Are they

    really
    > > different routines that the ones without the 'A' in the end?
    > > or is that just something the compiler adds??

    >
    > IIRC, "RegOpenKeyEx" is a macro that expands into different names
    > depending on whether you build for Unicode or not.
    >
    > Victor


    That solved the problem!!
    Thank you very much Victor!
    Harbinger of Doom, Jul 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,604
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    729
  3. Roedy Green

    poking and reading Windows Registry

    Roedy Green, Jul 19, 2003, in forum: Java
    Replies:
    1
    Views:
    869
    Eugene Toporov
    Jul 22, 2003
  4. Leny
    Replies:
    3
    Views:
    16,901
    Daniel
    Feb 1, 2005
  5. Collin Miller
    Replies:
    10
    Views:
    576
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page