MAKEINTRESOURCE((id>>4)+1) 是什么意思?

What is the meaning of MAKEINTRESOURCE((id>>4)+1)?

我正在尝试模仿 CString::LoadString(HINSTANCE hInst, DWORD id, WORD langID) 的行为,而不是在我的应用程序中引入对 MFC 的依赖。所以我浏览了源代码。它做的第一件事是立即调用 AtlGetStringResourceImage(hInst, id, langID),然后这又包含以下代码行:

    hResource = ::FindResourceExW(hInst, (LPWSTR)RT_STRING, MAKEINTRESOURCEW((id>>4)+1), langID);

(不是一字不差,删掉了一些不重要的东西)

ID移4加1是什么意思?根据 FindResourceEx 的文档,您应该传入 MAKEINTRESOURCE(id),我找不到任何在将 id 传递给 MAKEINTRESOURCE 之前对其进行操作的示例代码。同时,如果我让我的代码调用 MAKEINTRESOURCE(id) 那么它不起作用并且 FindResourceEx returns 为 null,而如果我使用上面的 shift + add,那么它就可以工作。

谁能解释一下?

来自 STRINGTABLE resource 文档:

RC allocates 16 strings per section and uses the identifier value to determine which section is to contain the string. Strings whose identifiers differ only in the bottom 4 bits are placed in the same section.

您感兴趣的代码通过忽略低 4 位来定位存储给定字符串标识符的部分。