Why does MAKEINTRESOURCE() work?

后端 未结 3 1550
清歌不尽
清歌不尽 2020-12-03 14:00

The macro is defined as:

#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
         


        
3条回答
  •  半阙折子戏
    2020-12-03 14:03

    This works because Windows doesn't allow mapping pages for the first 64 KB of the address space. To catch null pointer references. But I think also to catch pointer bugs in programs that were converted from the 16-bit version of Windows.

    A side-effect is that this allows to reliably distinguish resource IDs packed into a pointer value since they'll always point to non-mappable memory.

提交回复
热议问题