为什么MAKEINTRESOURCE()工作? [英] Why does MAKEINTRESOURCE() work?
问题描述
宏定义为:
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
怎么会这可以被用来指示是资源ID(16位无符号整数)或它的名字(一个指向字符数组)?
不这样有效限制的地址空间(32位系统),以16位?否则,系统怎样知道我是否使用ID或名字?
How come this can be used to indicate either a resource ID (a 16-bit unsigned int) or its name (a pointer to an array of char)? Doesn't this effectively limit the address space (on a 32-bit system) to 16-bit? Otherwise how does the system know whether I'm using an ID or a name?
推荐答案
这工作,因为Windows不允许的第一个64 KB的地址空间映射页。为了赶上空指针引用。但我认为还搭上指针漏洞在被从Windows的16位版本的转换程序。
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.
一个副作用是,这允许可靠地区分包装成一个指针值的资源ID,因为他们永远指向非可映射内存。
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.
这篇关于为什么MAKEINTRESOURCE()工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!