問題描述
宏定義為:
#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() 有效?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!