Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
3.22/5 (2 votes)
See more:
Given a line like this:
C++
bitmapHandle = (HBITMAP) ::LoadImage(app->instance(),
            MAKEINTRESOURCE(resourceID), IMAGE_BITMAP, 0, 0,
            LR_DEFAULTSIZE|LR_CREATEDIBSECTION);


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!
Posted
Comments
Richard MacCutchan 28-Sep-14 4:20am    
Your syntax is wrong, you need to use a #define for the resource compiler.
David O'Neil 28-Sep-14 5:43am    
So it is only for the resource compiler itself? That compiler is constrained to using #defines, and somehow maps '103', or whatever number is used to something different than a const int or other declaration, and then the MAKEINTRESOURCE gets hung up on that difference? I'd like to understand that better if you know of any links... (Googling "microsoft resource compiler requires defines" isn't very helpful.) Thanks.
Richard MacCutchan 28-Sep-14 7:30am    
See below.

1 solution

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[^].
 
Share this answer
 
Comments
David O'Neil 28-Sep-14 9:28am    
5-d and Accepted. For clarity, the specific subpage is http://msdn.microsoft.com/en-us/library/aa381033.aspx, where it says (paraphrased) "'#define' in a Resource Compiler file defines a specified name by assigning it a given value." It continues on to say,

"RC treats files with the .c and .h extensions in a special manner. It assumes that a file with one of these extensions does not contain resources. If a file has the .c or .h file name extension, RC ignores all lines in the file except the preprocessor directives."

Thanks for pointing my in the right direction!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900