LoadImage not loading animated cursor from resources when statically linking to MFC
-
This is very strange problem because my code works perfectly when dynamically linking to MFC. At some point in my project I use:
HCURSOR hAniCur = (HCURSOR)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_HOURGLASS), IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);which gives me a valid handle as long as MFC is in a DLL, but returns NULL when I link static MFC libraries. There are no differences between Debug or Release builds, both suffer the same problem. I also tried to change the resource ID of the animated cursor and to use a string instead of a number, but without success. I have reproduced this problem on a little test project if anyone likes the challenge... Thanks in advance, Paolo
-
This is very strange problem because my code works perfectly when dynamically linking to MFC. At some point in my project I use:
HCURSOR hAniCur = (HCURSOR)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_HOURGLASS), IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);which gives me a valid handle as long as MFC is in a DLL, but returns NULL when I link static MFC libraries. There are no differences between Debug or Release builds, both suffer the same problem. I also tried to change the resource ID of the animated cursor and to use a string instead of a number, but without success. I have reproduced this problem on a little test project if anyone likes the challenge... Thanks in advance, Paolo
Step through AfxGetResourceHandle() and make sure it's returning the correct HINSTANCE. I've seen that function return unexpected results before, which then causes all sorts of resource headaches.
-
Step through AfxGetResourceHandle() and make sure it's returning the correct HINSTANCE. I've seen that function return unexpected results before, which then causes all sorts of resource headaches.
I tried with AfxGetInstanceHandle(), AfxGetResourceHandle() and GetModuleHandle(NULL). They all return the same value, that is 0x00400000, which is right. What's more, loading from a file works just fine with the arguments I pass to the function. It seems like LoadImage can't find the resource, but why? When I link with static libraries I add some resources to my executable, so I thought something was in conflict with the animated cursor resource. I tried with different IDs, but without any luck. I imported the animated cursor as a custom resource, naming that type "ANICURSOR". Is this right? Or I should use something else? I think the correct resource type is RT_ANICURSOR, but how can I add such resources to my project? However, loading the animated cursor with the type I specified works in Debug version. Any other ideas?
-
This is very strange problem because my code works perfectly when dynamically linking to MFC. At some point in my project I use:
HCURSOR hAniCur = (HCURSOR)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_HOURGLASS), IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);which gives me a valid handle as long as MFC is in a DLL, but returns NULL when I link static MFC libraries. There are no differences between Debug or Release builds, both suffer the same problem. I also tried to change the resource ID of the animated cursor and to use a string instead of a number, but without success. I have reproduced this problem on a little test project if anyone likes the challenge... Thanks in advance, Paolo
I discovered what was wrong: if there are static cursor resources (RT_CURSOR) both LoadImage() and LoadCursor() don't look for animated cursor resources (RT_ANICURSOR = 21). Statically linking to MFC involves the inclusion of some MFC resources, among which there are two cursors for context-sensitive help. I've tried adding the animated cursor as a static cursor, but both VC++ IDE and the resource compiler recognize the internal file format. So what should I do, if I don't want to load the cursor from file? Is this a BUG ?? (tested on Win95 and Win2000) Any suggestion would be appreciated... :(
-
This is very strange problem because my code works perfectly when dynamically linking to MFC. At some point in my project I use:
HCURSOR hAniCur = (HCURSOR)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_HOURGLASS), IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);which gives me a valid handle as long as MFC is in a DLL, but returns NULL when I link static MFC libraries. There are no differences between Debug or Release builds, both suffer the same problem. I also tried to change the resource ID of the animated cursor and to use a string instead of a number, but without success. I have reproduced this problem on a little test project if anyone likes the challenge... Thanks in advance, Paolo
To solve the problem, I thought to load the animated cursor resource and then create the cursor handle with the following code:HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_HOURGLASS), RT_ANICURSOR); DWORD dwResSize = SizeofResource(NULL, hResInfo); HGLOBAL hRes = LoadResource(NULL, hResInfo); PBYTE pResData = (PBYTE)LockResource(hRes); HCURSOR hAniCur = CreateIconFromResourceEx(pResData, dwResSize, FALSE, 0x00030000, 32, 32, LR_DEFAULTCOLOR); The problem remains :( All the instruction are successful with both types of linkage, but the last returns a valid handle only when dynamically linking to MFC. When I specify to use static MFC libraries, CreateIconFromResourceEx() cease to work and returns NULL. Can anyone tell me why? I tried to debug USER32 code, but it's a suicide without debug symbols. Where can I get debug symbols for Windows 2000? Please help!!
-
I tried with AfxGetInstanceHandle(), AfxGetResourceHandle() and GetModuleHandle(NULL). They all return the same value, that is 0x00400000, which is right. What's more, loading from a file works just fine with the arguments I pass to the function. It seems like LoadImage can't find the resource, but why? When I link with static libraries I add some resources to my executable, so I thought something was in conflict with the animated cursor resource. I tried with different IDs, but without any luck. I imported the animated cursor as a custom resource, naming that type "ANICURSOR". Is this right? Or I should use something else? I think the correct resource type is RT_ANICURSOR, but how can I add such resources to my project? However, loading the animated cursor with the type I specified works in Debug version. Any other ideas?
Convert the image to one of the closest DIB format, and then use StretchDIBits to display it. My guess is that each pixel is a 16-bit grayscale level, so the closest DIB format would be 8-bit grayscale image, or a 256-color DIB with a grayscale color table. Setup a BITMAPINFO structure with a 256-color grayscale color table, convert the image array to a 64x64 BYTE array, and then use StretchDIBits to display it.