Post by Sudeshhow to inlcude a plain text file as resource
You have to declare the filename in a .rc file that you then add to the
project. The .rc file defines an ID number for the resource so your code
can find it later.
Post by Sudeshand then read it in program?
Use the Win32 API FindResource(), LoadResource(), and LockResource()
functions, or the VCL's TResuorceStream class.
--- myfile.rh ---
#ifndef MyFileH
#define MyFileH
#define ID_MYFILE 12345
#endif
--- myfile.rc ---
#include "myfile.rh"
ID_MYFILE RCDATA "myfile.txt"
--- mysrc.cpp ---
#include "myfile.rh"
{
HRSRC hSrc = FindResource(NULL, MAKEINTRESOURCE(ID_MYFILE),
RT_RCDATA);
if( hSrc )
{
HGLOBAL hData = LoadResource(NULL, hSrc);
if( hData )
{
LPVOID pData = LockResource(hData);
DWORD dwSize = SizeofResource(NULL, hSrc);
// use pData as needed, up to dwSize bytes...
}
}
}
or:
{
TResourceStream *strm = new TResourceStream(0, ID_MYFILE,
RT_RCDATA);
// use strm as needed...
delete strm;
}
Gambit