Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

Removing Certain warning

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 27 Oct 2006 22:47 GMT
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)
Bruno van Dooren [MVP VC++] - 28 Oct 2006 09:34 GMT
>    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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

David Wilkinson - 28 Oct 2006 11:28 GMT
> Hey There,
>     I have this line of code:
[quoted text clipped - 9 lines]
>   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
Jay - 31 Oct 2006 15:51 GMT
> > Hey There,
> >     I have this line of code:
[quoted text clipped - 16 lines]
>
> 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)
Bruno van Dooren [MVP VC++] - 31 Oct 2006 19:22 GMT
>> > 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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Jay - 31 Oct 2006 19:38 GMT
> >> > retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey,0,KEY_READ,&OpenKey);
>
[quoted text clipped - 17 lines]
>     bruno_nos_pam_van_dooren@hotmail.com
>     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)
Bruno van Dooren [MVP VC++] - 01 Nov 2006 09:30 GMT
> Thanks for the input, but when I set the line to:
> retVal =
[quoted text clipped - 7 lines]
>
> 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?

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Jay - 01 Nov 2006 15:56 GMT
> > Thanks for the input, but when I set the line to:
> > retVal =
[quoted text clipped - 32 lines]
>     bruno_nos_pam_van_dooren@hotmail.com
>     Remove only "_nos_pam"

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

-Jay
(patelj27b at gmail dot com)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.