简体   繁体   English

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

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

I am trying to mimic the behavior of CString::LoadString(HINSTANCE hInst, DWORD id, WORD langID) without introducing a dependency on MFC into my app.我试图模仿CString::LoadString(HINSTANCE hInst, DWORD id, WORD langID)的行为,而不会将对 MFC 的依赖引入我的应用程序。 So I walked through the source.所以我遍历了源头。 The first thing it does is to immediately call AtlGetStringResourceImage(hInst, id, langID) , and then this in turn contains the following line of code:它做的第一件事是立即调用AtlGetStringResourceImage(hInst, id, langID) ,然后这又包含以下代码行:

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

(It's not verbatim like this, but I trimmed out some unimportant stuff). (不是这样逐字逐句的,但我删掉了一些不重要的东西)。

What is the meaning of shifting the ID by 4 and adding 1?把ID移4加1是什么意思? According to the documentation of FindResourceEx, you should pass in MAKEINTRESOURCE(id) , and I can't find any example code that is manipulating the id before passing it to MAKEINTRESOURCE .根据 FindResourceEx 的文档,您应该传入MAKEINTRESOURCE(id) ,并且在将其传递给MAKEINTRESOURCE之前,我找不到任何正在操纵 id 的示例代码。 At the same time, if I make my code call MAKEINTRESOURCE(id) then it doesn't work and FindResourceEx returns null, whereas if I use the above shift + add, then it does work.同时,如果我让我的代码调用MAKEINTRESOURCE(id)那么它不起作用并且FindResourceEx返回 null,而如果我使用上面的 shift + add,那么它确实起作用。

Can anyone explain this?谁能解释一下?

From the STRINGTABLE resource documentation:来自STRINGTABLE 资源文档:

RC allocates 16 strings per section and uses the identifier value to determine which section is to contain the string. RC 为每个部分分配 16 个字符串,并使用标识符值来确定哪个部分将包含该字符串。 Strings whose identifiers differ only in the bottom 4 bits are placed in the same section.标识符仅在低 4 位上不同的字符串被放置在同一部分中。

The code you are curious about locates the section a given string identifier is stored in by ignoring the low 4 bits.您感兴趣的代码通过忽略低 4 位来定位存储给定字符串标识符的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM