Archived

This topic is now archived and is closed to further replies.

Boltimus

Getting bytes from resources

Recommended Posts

Boltimus    100
Ok, so I got my resources loaded into MS VC 6.0 and am trying to get to the actual bytes of the resource, but I am having difficulties. It''s not a standard type, basically I''ve added a text file as a resource and am trying to get to the bytes of it. so here''s what I''m trying to do...
 HGLOBAL resrc_ptr;
         HRSRC   Hrsrc;
         resrc_ptr = LoadResource(NULL, Hrsrc);
	 COB_OBJECT_RESOURCE_ptr = LockResource(resrc_ptr); 
the thing is, when I check the return value of resrc_ptr, it is NULL, which in so many words means that it is failing. Has anyone else had to access the data from a non-standard resource file and done it successfully. I''ve been looking up and down the MSDN, but it doesn''t seem to address resources that are non-standard and are that in your .exe file. It just goes over what to do if it is in another module... Please help... ~Bolt ~Bolt "All men dream: but not equally. Those who dream by night in the dusty recesses of their minds wake in the day to find that it was vanity: but the dreamers of the day are dangerous men, for they may act their dreams with open eyes, to make it possible." This I did...

Share this post


Link to post
Share on other sites
LessBread    1415
According to the docs for LoadResource, the HRSRC handle should be returned from FindResource or FindResourceEx

HRSRC FindResource(
HMODULE hModule, // module handle
LPCTSTR lpName, // resource name
LPCTSTR lpType // resource type
);

The resource type that you want to use is RT_RCDATA, but you should read the remarks section of the docs for that function as there are a few things to note about it''s use.

At any rate, to put this all together:

HGLOBAL resrc_ptr;
HRSRC Hrsrc = FindResource(NULL, "MyDataName", RT_RCDATA);
resrc_ptr = LoadResource(NULL, Hrsrc);
COB_OBJECT_RESOURCE_ptr = LockResource(resrc_ptr);

Share this post


Link to post
Share on other sites