Why does MAKEINTRESOURCE () work?

A macro is defined as:

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

Why can this be used to indicate a resource identifier (16-bit unsigned int) or its name (pointer to an array from char)? Doesn't that limit the address space (on a 32-bit system) to 16 bits? Otherwise, how does the system know if I am using an identifier or name?

+15
source share
3 answers

This works because Windows does not allow pages to be displayed for the first 64 KB of address space. Catch references to null pointers. But I think that also catch pointer errors in programs that were converted from a 16-bit version of Windows.

, , , .

+19

MAKEINTRESOURCE . . API , . API- C , , :

HICON LoadIcon(HINSTANCE hInstance,LPCTSTR lpIconName);
HICON LoadIcon(HINSTANCE hInstance,UINT resourceId);

, API , MAKEINTRESOURCE API. , :

HICON LoadIconByName(HINSTANCE hInstance,LPCTSTR lpIconName);
HICON LoadIconById(HINSTANCE hInstance,UINT resourceId);

, Windows API. . API , .

+14

Yes, this limits the address space, but not as much as you think. They effectively cut out 64 KB of your 4 GB of address space. Most, if not all, of this 64K is already reserved for other things on Windows, so effective loss is nothing.

In general, this is a space saving because they do not need an extra bit of information to distinguish between a pointer and an integer identifier. It was invented in the bad old days, when the space was on top.

+4
source

All Articles