Removing Certain warning

J

Jay

Hey There,
I have this line of code:
retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

and it produces this warning:
warning C4312: 'type cast' : conversion from 'DWORD' to 'HKEY'
of greater size


What can I do to have this warning be removed?

Thanks!
Jay
(patelj27b at gmail dot com)
 
B

Bruno van Dooren [MVP VC++]

I have this line of code:
retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

and it produces this warning:
warning C4312: 'type cast' : conversion from 'DWORD' to 'HKEY'
of greater size

Hi,
what is the type of RetVal?
RegOpenKeyEx returns a long, not a HKEY. if retVal is a HKEY, that would be
the cause of the problem.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
D

David Wilkinson

Jay said:
Hey There,
I have this line of code:
retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

and it produces this warning:
warning C4312: 'type cast' : conversion from 'DWORD' to 'HKEY'
of greater size


What can I do to have this warning be removed?

Thanks!
Jay
(patelj27b at gmail dot com)

Jay:

You need to show us more code. What are the declared types of all the
variables in this line of code?

David Wilkinson
 
J

Jay

David said:
Jay:

You need to show us more code. What are the declared types of all the
variables in this line of code?

David Wilkinson

Hey There,
retVal is declared as a long, subKey is a char [46], and OpenKey is
HKEY. I don't think these have anything to do with it, from what I can
tell it has to do with HKEY_LOCAL_MACHINE being a constant with an int
value, and needing to be of type "HKEY". Any ideas?

Thanks!
Jay
(patelj27b at gmail dot com)
 
B

Bruno van Dooren [MVP VC++]

retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);
retVal is declared as a long, subKey is a char [46], and OpenKey is
HKEY. I don't think these have anything to do with it, from what I can
tell it has to do with HKEY_LOCAL_MACHINE being a constant with an int
value, and needing to be of type "HKEY". Any ideas?

If that is the case, then you can solve the problem with a simple explicit
typecast i think.
(INT_PTR)HKEY_LOCAL_MACHINE

Are you doing this on x64 perhaps?
Because otherwise a handle should be the same size as a DWORD on x386,
unless I am missing something obvious.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
J

Jay

Bruno said:
retVal is declared as a long, subKey is a char [46], and OpenKey is
HKEY. I don't think these have anything to do with it, from what I can
tell it has to do with HKEY_LOCAL_MACHINE being a constant with an int
value, and needing to be of type "HKEY". Any ideas?

If that is the case, then you can solve the problem with a simple explicit
typecast i think.
(INT_PTR)HKEY_LOCAL_MACHINE

Are you doing this on x64 perhaps?
Because otherwise a handle should be the same size as a DWORD on x386,
unless I am missing something obvious.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"

Thanks for the input, but when I set the line to:
retVal =
RegOpenKeyEx((INT_PTR)HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

I just get the error:
error C2664: 'RegOpenKeyExA' : cannot convert parameter 1 from
'INT_PTR' to 'HKEY'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast

Is there something else I should do?

-Jay
(patelj27b at gmail dot com)
 
B

Bruno van Dooren [MVP VC++]

Thanks for the input, but when I set the line to:
retVal =
RegOpenKeyEx((INT_PTR)HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

I just get the error:
error C2664: 'RegOpenKeyExA' : cannot convert parameter 1 from
'INT_PTR' to 'HKEY'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast

Is there something else I should do?

D'oh.
That what you get when posting with a head full of snot.
Of course I meant
(HKEY)HKEY_LOCAL_MACHINE

But I just checked that constant, and it is defined like this:
(( HKEY ) (ULONG_PTR)((LONG)0x80000002) )
So I don't think the parameter is the problem.

To be sure, I just compiled this with /W4, and got no warnings.
char subKey[] = "test";
HKEY OpenKey;
DWORD retVal =
RegOpenKeyExA(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

What version of VC++ are you using, and are you really sure that retVal is a
DWORD?

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
J

Jay

Bruno said:
Thanks for the input, but when I set the line to:
retVal =
RegOpenKeyEx((INT_PTR)HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

I just get the error:
error C2664: 'RegOpenKeyExA' : cannot convert parameter 1 from
'INT_PTR' to 'HKEY'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast

Is there something else I should do?

D'oh.
That what you get when posting with a head full of snot.
Of course I meant
(HKEY)HKEY_LOCAL_MACHINE

But I just checked that constant, and it is defined like this:
(( HKEY ) (ULONG_PTR)((LONG)0x80000002) )
So I don't think the parameter is the problem.

To be sure, I just compiled this with /W4, and got no warnings.
char subKey[] = "test";
HKEY OpenKey;
DWORD retVal =
RegOpenKeyExA(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);

What version of VC++ are you using, and are you really sure that retVal is a
DWORD?

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"

Mr. Van Dooren,
I am currently using Visual Studio 2003

-Jay
(patelj27b at gmail dot com)
 

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

Top