For those of you who dont know, various types of files can be appended to DLL's and executables. Visual Studio makes it easy by allowing files to be added using its IDE. The harder way is to use a resource hacker to append the resource to the DLL or executable.
Anyway, bitmaps are one type that can be stored. Which means, if the bitmaps from within the file can be used, your graphics can be a lot more secure.
The following messy C code is a routine I knocked up to extract the bitmap from an executable and save it to a file. Its messy because I haven't totally figured out the layout of bitmaps in resources yet, and I've justed tested it with one bitmap at the moment.
I present for your amusement the following :
hExe = LoadLibrary("C:TEST.EXE");
if (hExe == NULL)
{
MessageBox("Could not load exe.","*",MB_OK);
}
else
{
HRSRC hResLoad;
char *lpResLock;
char *f;
FILE *j;
int x;
#pragma pack(2)
struct {
char header[2];
long l1;
WORD w1;
WORD w2;
long l2;
long l3;
WORD width;
WORD height;
WORD w3;
WORD w4;
} header;
#pragma pack()
WORD offset;
int PadSize,index,y,Width,Height;
// Locate the dialog box resource in the .EXE file.
sprintf(t,"#%d",IDB_BITMAP1);
hrscr=FindResource((HMODULE) hExe,t,RT_BITMAP);
MessageBox((hrscr ? "Yes" : "No"),"*",MB_OK);
hResLoad = (HRSRC) LoadResource((HMODULE) hExe, hrscr);
if (hResLoad==NULL) MessageBox("no","*",MB_OK);
lpResLock = (char *) LockResource(hResLoad);
if (lpResLock==NULL) MessageBox("no","*",MB_OK);
j=fopen("c:p.BMP","wb");
// Write the header
Width=128;
Height=128;
PadSize=4-((Width*3) % 4);
if (PadSize==4) PadSize=0;
memcpy(header.header,"BM",2);
header.l1=26+( ((Width*3)+PadSize) * Height );
header.w1=0;
header.w2=0;
header.l2=26;
header.l3=12;
header.width=Width;
header.height=Height;
header.w3=1;
header.w4=24;
f=(char *) &header;
for (x=0; x<sizeof(header); x++)
{
fputc((int) *(f+x),j);
}
memcpy((char *) &offset,(char *) lpResLock,2);
index=offset;
{
char t[256];
sprintf(t,"[%d]",index);
MessageBox(t,"*",MB_OK);
}
for (y=0; y<Height; y++)
{
for (x=0; x<Width*3; x++)
{
fputc(*(lpResLock+index),j);
index++;
}
if (PadSize)
{
for (x=0; x<PadSize; x++)
{
fputc((int) 0,j);
}
}
}
fclose(j);
As you can see its still got all my comments in, and at the moment its not too efficient.
However, the general theory is there.
In order for it to be used in DBPro, the bitmap would need to be extracted, loaded and then immediately deleted, thus presenting no outwardly sign of temporary files being used.
In addition, it could also be used other things, like sound data, mesh data etc etc.
By the way, I use part of IanM's SaveBitmap code...
The place for all
great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me