473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 "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
Jul 19 '05 #1
1 19812

"Victor Bazarov" <v.********@attAbi.com> schreef in bericht
news:vg************@corp.supernews.com...
"Harbinger of Doom" <sl******@pandora.be> 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_R EAD, &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!
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Duncan Allen | last post by:
I'm trying to use aspnet_setreg to encrypt user names & password used in the web.config file for use in the indentity element. When the website runs I get the message 'Error reading the password...
3
by: Mike Malter | last post by:
On my XP Professional dev machine, I am able to read the registry by giving permissions to the ASP.NET account on the local machine. When I transfer the code to my staging server (Windows 2003),...
5
by: Dhilip Kumar | last post by:
Hi All, I'm writing a Windows Service app using C#. I need to read some configuration settings before the service starts up. These settings will be used by the service in its operation. ...
1
by: Peter John | last post by:
I am using the following code to read from and write to the registry. The writing works fine but reading always fails. Can anyone suggest what is going wrong? Imports Microsoft.Win32 Public...
3
by: Ahmad Jalil Qarshi | last post by:
Hi! I am developing an application in C# as a windows NT Service. This application needs to check for eventlog using EventLog.Exists("System") But unfortunately it generates exception...
0
by: Simon Beetham | last post by:
Hi all, My little application is in VB2005 Pro. I'm doing my development on WinXP 64-bit. I was having a problem reading a registry key under HKLM and thought it was a permission issue. ...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
0
by: tmsprowl | last post by:
Greetings! I was wondering if someone could help me with a problem I'm having. My department is just one of many within my organization. My organization has control over the network domain,...
4
by: RhavoX | last post by:
Hi. This may be a very stupid question but I'll leave you to judge it ;) I know there were lots of questions about this but none of the answers suits me. I'm wondering how to get the BINARY type...
29
by: Guillaume Dargaud | last post by:
Hello all, anybody knows if there's some ANSI-C conformant code around that can read Windows-style .ini files ? I don't care about writing to it but I need to be able to read it from various OSs,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.