提供unsigned int时,LoadImage会失败,但适用于#define [英] LoadImage fails when supplied unsigned int but works for #define
问题描述
给出如下这样的一行:
Given a line like this:
bitmapHandle = (HBITMAP) ::LoadImage(app->instance(),
MAKEINTRESOURCE(resourceID), IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE|LR_CREATEDIBSECTION);
如果 resourceID
LoadImage 会失败>最终不是 #defined?
换句话说,如果标题定义文件定义传递给函数的值为 #define THE_RESOURCE 103
,然后它可以工作,即使它作为 DWORD
或 unsigned int
在整个调用者中传递。但是,如果我将资源文件中的定义更改为 const WORD THE_RESOURCE = 103
,或者是unsigned int或其他类型,则 LoadImage
失败了?
我几分钟后对着它头撞了一下,我比什么都好奇。据我所知, MAKEINTRESOURCE
正在使用相同的确切数字进行魔术,这是工作版和非工作版中唯一不同的项。
谢谢!
Why would the LoadImage
fail if the resourceID
is not ultimately #defined?
In other words, if the header definition file defines the value passed into the function as #define THE_RESOURCE 103
, then it works, even if it is passed throughout the callers as a DWORD
or unsigned int
. But if I change the definition in the resource file to const WORD THE_RESOURCE = 103
, or an unsigned int, or another type, the LoadImage
fails?
I'm curious more than anything, after butting my head against it for a couple minutes. As far as I can see, MAKEINTRESOURCE
is doing its magic on the same exact number, and that is the only item that is different in the working and non-working version.
Thanks!
推荐答案
程序文件中的所有资源都可以通过名称访问(作为字符串)或者整数值。如果任何名称都没有#define
语句,则资源编译器会将该名称存储在资源部分中。如果您尝试通过数字(由C ++const int
语句定义)引用该项目,系统将找不到匹配项。
您可以在 http://msdn2.microsoft找到有关资源文件的更多信息。 .com / zh-CN / library / aa380599.aspx [ ^ ]。
All resources in a program file are accessed by their name (as a string) or by an integer value. If there is no#define
statement for any name, then the resource compiler will store the name in the resource section. If you then try to refer to that item by a number (defined by a C++const int
statement) the system will not find a match.
You can find more information on Resource Files at http://msdn2.microsoft.com/en-us/library/aa380599.aspx[^].
这篇关于提供unsigned int时,LoadImage会失败,但适用于#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!