Now I'm having some problem working with ressource files! I heard that we could use these to place files like pictures and audio inside a .rc file, so that we can then execute our application without having to carrying around dlls and others. Is this true? Could be interesting! :D
But the problem here is that I can't get to place or use files in ressources! I'm using MS-VC++ 2003, and when I add a .rc file to the project, I can try to add images, audio inside of the .rc, but I don't know how to use them in my code! I know I have to use some special syntax depending on the type of file, but what if you have to import some files like .png?
So do anyone here knows all to deal with ressources and give a syntax example, or are ressources files just serving for other things???
Moved to Windows board.
msdn: About Resource Files.
msvc2003 has a gui resource editor so you don't need to fiddle around with resource scripts, unless you particularly want to. Check out your compiler documentation for precise help. Some resource types are supported directly, for example images such as bitmaps or icons. For those resource types not directly supported you can use RCDATA.
Search this board for examples of the use of resource definition statements and how to use resources as this sort of thing comes up quite a lot.
I still don't understand anything. I searched in the forums and it seems that resources files can only serve for windows specific functions like doing icons and listboxs and stuff. But the problem is that I'm using image loading functions from SDL, (2D kind of game engine) and the function actually receive a parameter of char*...
So if I try to put this kind of code for the function, it can't work...
So I believe I have to use the correct syntax:
This way everything works fine, but is there a way to make the compiler "think" that "image1.png" is actually a file inside of itself(.exe)? Remember I have to pass a char*! :(
(And I tried RCDATA but I think that this can't still pass a char* to the function...)
The resource will not have a file name as such as it is included in your exe (and makes it bigger).
If you have a lot of image/sound resources becareful not to make your exe too big (and hard to distribute).
You could always write the resource data to a temp file and send to your image loader as required. Remembering that file I/O is _much_ slower than memory I/O.
>>I'm using image loading functions from SDL,
Why? Why not use LoadImage()
//load a bitmap
hImage=LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_IMAGE1), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
If you have to use PGN try GDI+
This is some code I have hacked together from MSDN examples, don't expect it to WORK....
using namespace Gdiplus;
int WriteResourceAsPGN(int iResourceID,char *szFullFileName)
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
//load image from resource
HBITMAP hImage=LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(iResourceID), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Image* image = new Image(hImage);
// Get the CLSID of the PNG encoder.
stat = image->Save(szFullFileName, &encoderClsid, NULL);
if(stat == Ok)
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
*pClsid = pImageCodecInfo[j].Clsid;
return j; // Success
return -1; // Failure
well, I have to use the function IMG_Load... because I make ALL my game with the SDL library. I can't just switch between other ways of doing things, because I believe that "LoadImage" returns an "HBITMAP "?
And SDL doesn't handle this type of variable... And I'm planning to keep up with working with this lib...
But for memory I/O or file I/O, I believe it doesn't change things up, because at start I load up everything I need from my files, and I'll practically won't ever have other need of loading them after that, and it won't take much than 30 Mb...
And for distribution of the app, if you have your files in other folders or inside the .exe, it won't change the size of the whole project :D (Unless we're talking about the .cpp, .lib, .h :) )
Thanks anyway for taking time with this thread!