Questions regarding "warning C4312: 'type cast'"

Viewed 14487

This is the code I have:

HWND WebformCreate(HWND hParent, UINT id)
{
    return CreateWindowEx(0, WEBFORM_CLASS, _T("about:blank"),
        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, 100, 100, hParent,
        (HMENU)id, GetModuleHandle(NULL), 0);
}

This is the warning I get:

warning C4312: 'type cast' : conversion from 'UINT' to 'HMENU' of greater size

These are the questions I have:

  1. Why does the compiler think it's a bad idea to cast to a bigger type?
  2. What's the best way to get rid of the warning? (I don't want to disable it.)
  3. Doing a double type cast like this: (HMENU)(UINT_PTR)id gets rid of the warning. Why/how?
  4. Disabling "Detect 64-bit Portability Issues" (Wp64) also gets rid of the warning. Why is Wp64 deprecated? Should I have it on?
3 Answers
Related