Adding a resource inside application.
Posted on 2003-11-06
My application at a certain point needs a bitmap file. This bitmap file has to be in the directory where the application starts. If not the application raise an exception.
In the case of accidental deletion of the bitmap file i putted that 'bmp' in a resource file.
I used brcc32.exe.
Brcc32 read my rc file (Image.rc) where i wrote the following :
Image.rc ===> (Un5 BITMAP Un5.bmp).
Inside the application i tried to call the resource Image to create that bitmap file everytime the program starts in the starting directory.
There is 1 problem.
Although the file creation part is ok. The first 14 bytes are missing (I think the file header). And that thing cause the raise of the exception i mentioned before, (file is unreadable). I need the whole bitmap file to be created and i dont know whats wrong with the code ... i replaced RT_BITMAP with RT_RCDATA and same the same thing happened.
Here is the code i use :
procedure TForm2.FormCreate(Sender: TObject);
rStream := TResourceStream.Create(hInstance, 'un5', RT_BITMAP);
fStream := TFileStream.Create(fname1, fmCreate);
EXCEPT on E: Exception do