为什么 MAKEINTRESOURCE() 有效? [英] Why does MAKEINTRESOURCE() work?

查看:31
本文介绍了为什么 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() 有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆