Hanan
Hanan

Reputation: 1179

FindResource() doesn't find my resource

I have some code template that i compiled, i would like to understand one part of the code that i am can't figure out what it does although i have spent a whole day tried to.

the code in question is as follows:

#define IDR_STUB 1
hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_STUB), "STUB");

I have another two files in the same directory as the main file, the first one is called `something.rc' and is content is:

#define IDR_STUB 1
IDR_STUB STUB DISCARDABLE "stub.exe"

The other file as you can guess is stub.exe.

My question is what is wrong with the FindResource call above that it can't find whatever is trying to find, I have hard time to understand how that function is suppose to work.

So if you can give me some help i would be glad :)

THX.

Upvotes: 0

Views: 2063

Answers (2)

vadim_hr
vadim_hr

Reputation: 549

I've stuck in the same issue, when tried to use predefined resource type RC_DATA.

FindResource(hInst, MAKEINTRESOURCE(name), RT_RCDATA);

This code was returning NULL whatever I did.

So when you edit your .rc file you should use constant RCDATA, but when you call FindResource() you should use constant RT_RCDATA. Be careful. Hope I've helped someone.

Upvotes: 1

Sergey Podobry
Sergey Podobry

Reputation: 7189

Had the same problem. I solved it by using string resource id as described in MSDN:

If the first character of the string is a pound sign (#), the remaining characters represent a decimal number that specifies the integer identifier of the resource's name or type. For example, the string "#258" represents the integer identifier 258.

So try the following code:

hRsrc = FindResource(NULL, "#1", "STUB");

Upvotes: 2

Related Questions