error C2051: case expression not constant in VS2010

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShyamKrishnegowda
    New Member
    • Mar 2010
    • 3

    #1

    error C2051: case expression not constant in VS2010

    Hi,

    In one of the function we are using switch statement

    as

    switch
    {

    case HRESULT_FROM_WI N32( ERROR_INVALID_N AME ) :
    }

    The above code compiles fine in Vs2008 but its giving error when port to VS2010.

    Error:error C2051: case expression not constant


    Thanks in advance...

    Regards,
    Shyam
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    the first hit in google for HRESULT_FROM_WI N32 (on msdn, unsurprisingly) contains this comment:

    HRESULT_FROM_WI N32(x) used to be a macro, however we now run it as an inline function
    // to prevent double evaluation of 'x'. If you still need the macro, you can use __HRESULT_FROM_ WIN32(x)

    And obviously result of function that is not constant can't be used as case label.

    Comment

    Working...