Click to See Complete Forum and Search --> : Using embeded resources


Andrew Truckle
April 13th, 1999, 03:48 AM
If I insert a binary file as an embed resource in my program, how can I then access this resource and if it was a standard binary file (or the equivalent).

I know I can use LoadResource/FindResource to retrieve a HGLOBAL handle, but how the hell do I use this to say, read one character, a string, x bytes of data?

Gomez Addams
April 13th, 1999, 12:57 PM
You might be able to use the RT_RCDATA type which is for application-defined
data. Try FindResource or FindResourceEx to get the handle and LoadResource
to load it and obtain a pointer to it in memory. From there you will have to implement
your own data extraction functions but those should not be too difficult as long as
you know the size of the items you are extracting. Just advance a pointer by that
amount every time you obtain an item and you will be aimed at the next item.
Here's one that will extract any data type and will treat the data as an array of
characters :

BYTE * ExtractItem( BYTE *pdata, BYTE *pdest, size_t itemsize )
{
memcpy( pdest, pdata, itemsize ); // copy data to destination
return pdata + itemsize; // aim at next item
}