Reading the windows registry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harbinger of Doom

    Reading the windows registry

    Hello,

    I'm currently working on a program that has to read values from the windows
    registry.
    I use the functions "RegOpenKey Ex", "RegCloseKe y" and "RegQueryValueE x" 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(HK EY_LOCAL_MACHIN E,"Software", 0,KEY_READ, ptr1);

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

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

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

    temp = RegCloseKey(*pt r3);

    temp = RegCloseKey(*pt r2);

    temp = RegCloseKey(*pt r1);
    }

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

    e:\nodelistcrea tor\nodelistrea der.h(46) : error C2664: 'RegOpenKeyExA' :
    cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    Types pointed to are unrelated; conversion requires
    reinterpret_cas t, C-style cast or function-style cast
    e:\nodelistcrea tor\nodelistrea der.h(52) : error C2664: 'RegOpenKeyExA' :
    cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    Types pointed to are unrelated; conversion requires
    reinterpret_cas t, C-style cast or function-style cast
    e:\nodelistcrea tor\nodelistrea der.h(58) : error C2664: 'RegQueryValueE xA' :
    cannot convert parameter 4 from 'const int' to 'unsigned long *'
    Conversion from integral type to pointer type requires
    reinterpret_cas t, 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 "RegOpenKey ExA" and
    "RegQueryValueE xA" (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

    #2
    Re: Reading the windows registry


    "Victor Bazarov" <v.Abazarov@att Abi.com> schreef in bericht
    news:vg3surcpqt o3c3@corp.super news.com...[color=blue]
    > "Harbinger of Doom" <slavearc@pando ra.be> wrote...[color=green]
    > > I'm currently working on a program that has to read values from the[/color]
    > windows[color=green]
    > > registry.
    > > I use the functions "RegOpenKey Ex", "RegCloseKe y" and "RegQueryValueE x"[/color]
    > for[color=green]
    > > that.
    > > If I can read the manual correctly (which I hope I can) I have to[/color][/color]
    include[color=blue][color=green]
    > > 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(HK EY_LOCAL_MACHIN E,"Software", 0,KEY_READ,[/color]
    > ptr1);[color=green]
    > >
    > > temp = RegOpenKeyEx(*p tr1,"JavaSoft", 0,KEY_READ, *ptr2);
    > >
    > > temp = RegOpenKeyEx(*p tr2,"Java Development Kit", 0,KEY_READ, *ptr3);
    > >
    > > temp = RegQueryValueEx (*ptr3,"Current Version", NULL, REG_SZ,[/color]
    > this->buffer,[color=green]
    > > *sizeOfBuffer);
    > >
    > > temp = RegCloseKey(*pt r3);
    > >
    > > temp = RegCloseKey(*pt r2);
    > >
    > > temp = RegCloseKey(*pt r1);
    > > }
    > >
    > > When I try to compile it, I get these errors:
    > >
    > > e:\nodelistcrea tor\nodelistrea der.h(46) : error C2664: 'RegOpenKeyExA' :
    > > cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '[/color]
    >
    > The function apparently needs a pointer to a pointer to HKEY__ and
    > you're trying to pass a pointer to HKEY__ to it.
    >[color=green]
    > > Types pointed to are unrelated; conversion requires
    > > reinterpret_cas t, C-style cast or function-style cast
    > > e:\nodelistcrea tor\nodelistrea der.h(52) : error C2664: 'RegOpenKeyExA' :
    > > cannot convert parameter 5 from 'struct HKEY__ *' to 'struct HKEY__ ** '
    > > Types pointed to are unrelated; conversion requires
    > > reinterpret_cas t, C-style cast or function-style cast
    > > e:\nodelistcrea tor\nodelistrea der.h(58) : error C2664:[/color][/color]
    'RegQueryValueE xA'[color=blue]
    > :[color=green]
    > > cannot convert parameter 4 from 'const int' to 'unsigned long *'
    > > Conversion from integral type to pointer type requires
    > > reinterpret_cas t, 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![/color]
    >
    > 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(HK EY_LOCAL_MACHIN E,"Software",0, KEY_READ, &key1);
    >
    > and so on.
    >[color=green]
    > >
    > > Also, the errors state something about the functions "RegOpenKey ExA" and
    > > "RegQueryValueE xA" (notice the 'A' in the end)
    > > The MSDN-library doesn't give any info on those routines. Are they[/color][/color]
    really[color=blue][color=green]
    > > different routines that the ones without the 'A' in the end?
    > > or is that just something the compiler adds??[/color]
    >
    > IIRC, "RegOpenKey Ex" is a macro that expands into different names
    > depending on whether you build for Unicode or not.
    >
    > Victor[/color]

    That solved the problem!!
    Thank you very much Victor!


    Comment

    Working...