Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Compiler error when defining enum for registry

Compiler error when defining enum for registry

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiowindows-adminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunny_vc
    wrote on last edited by
    #1

    Hi, I am using one of the registy class given in CP. The keys are defined in .h file like:

    enum Keys
    {
    classesRoot = HKEY_CLASSES_ROOT,
    currentUser = HKEY_CURRENT_USER,
    localMachine = HKEY_LOCAL_MACHINE,
    currentConfig = HKEY_CURRENT_CONFIG,
    users = HKEY_USERS,
    performanceData = HKEY_PERFORMANCE_DATA,
    dynData = HKEY_DYN_DATA
    };

    When I compile this in VC6.0 it compiles with no errors. But when I compile the same in visual studio 2003 it gives error like:" Constant expression is not intergral" If i cast like: "classesRoot=(int)HKEY_CLASSES_ROOT", it throws warning such as "pointer truncation from HEKY to int". How can I avoid the error.Please suggest.

    Regards, Sunil Kumar

    C 1 Reply Last reply
    0
    • S sunny_vc

      Hi, I am using one of the registy class given in CP. The keys are defined in .h file like:

      enum Keys
      {
      classesRoot = HKEY_CLASSES_ROOT,
      currentUser = HKEY_CURRENT_USER,
      localMachine = HKEY_LOCAL_MACHINE,
      currentConfig = HKEY_CURRENT_CONFIG,
      users = HKEY_USERS,
      performanceData = HKEY_PERFORMANCE_DATA,
      dynData = HKEY_DYN_DATA
      };

      When I compile this in VC6.0 it compiles with no errors. But when I compile the same in visual studio 2003 it gives error like:" Constant expression is not intergral" If i cast like: "classesRoot=(int)HKEY_CLASSES_ROOT", it throws warning such as "pointer truncation from HEKY to int". How can I avoid the error.Please suggest.

      Regards, Sunil Kumar

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Try converting to ULONG_PTR or maybe LONG_PTR instead of int, althorough making an enum out of HKEYs seems to be a tiny-bit ugly to me, but this might just be my personal taste. Good luck.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      S 1 Reply Last reply
      0
      • C Code o mat

        Try converting to ULONG_PTR or maybe LONG_PTR instead of int, althorough making an enum out of HKEYs seems to be a tiny-bit ugly to me, but this might just be my personal taste. Good luck.

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        S Offline
        S Offline
        sunny_vc
        wrote on last edited by
        #3

        Thanks mate. (LONG_PTR) works.

        Regards, Sunil Kumar

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups