Reading the windows registry

  • Thread starter Harbinger of Doom
  • Start date
H

Harbinger of Doom

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!
 
H

Harbinger of Doom

Victor Bazarov said:
The function apparently needs a pointer to a pointer to HKEY__ and
you're trying to pass a pointer to HKEY__ to it.
'RegQueryValueExA'

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.


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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top