Why does MAKEINTRESOURCE() work?(为什么 MAKEINTRESOURCE() 有效?)
问题描述
宏定义为:
#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 映射页面.捕获空指针引用.但我认为还要捕捉从 16 位版本的 Windows 转换而来的程序中的指针错误.
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() 有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 MAKEINTRESOURCE() 有效?


基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01