Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a file into the Executable at runtime BCB 6

Status
Not open for further replies.

ironslave

Programmer
Feb 16, 2009
6
US
does anyone know how i would go about trying to Write a file into the Executable at runtime?

I cant find any information on this.... but then again i cant find any information on borland c++ builder at all... everyone is all about delphi
 
does anyone know how i would go about trying to Write a file into the Executable at runtime?

Can you please elaborate on this? I'm not sure I understand.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Look and see if this discussion is what you are looking for.

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
that is exactly what i was looking for, but that is confusing to understand, i have the code in my test program and it executes.... but the filesize of the program never changes and it messes up the file I am trying to upload...


---------------my version--------------
String Nome;
TCHAR Temp[MAX_PATH+1] = {0};
GetTempPath(MAX_PATH, Temp);


Nome = "C:\\wtf.exe";

TResourceStream *Resource = new TResourceStream((unsigned)HInstance, "STUB", RT_RCDATA);
Resource->SaveToFile(Nome);
delete Resource;

HANDLE H = BeginUpdateResource( "C:\\wtfe.exe", TRUE);
HANDLE FH = CreateFile("C:\\wtfe.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD Size = GetFileSize(FH, NULL);

BYTE *Buf = new BYTE[Size];

DWORD BR;
ReadFile(FH, Buf, Size, &BR, NULL);

CloseHandle(FH);
// i dont understand where it is saving this file?
UpdateResource(H, RT_RCDATA, "WTFE.exe" ,MAKEWORD(LANG_NEUTRAL, SUBLANG_NEUTRAL), Buf, Size);
delete[] Buf;
EndUpdateResource(H, FALSE);

----------------their version--------------------
String Nome;

if( Listview1->Items->Count < 2 )
return;

if( Form4->ShowModal() == 2 )
return;

TCHAR Temp[MAX_PATH+1] = {0};
GetTempPath(MAX_PATH, Temp);

Form4->Image1->Picture->Icon->SaveToFile(String(Temp) + "icone.ico");
case( Form4->RadioGroup1->ItemIndex )
{
case 0:
Nome = "exe";
break;
case 1:
Nome = "scr";
break;
case 2:
Nome = "com";
break;
case 3:
Nome = "bat";
break;
case 4:
Nome = "pif";
break;
case 5:
Nome = "cmd";
break;
}

Nome = ExtractFilePath(ParamStr(0)) + "Bindado." + Nome;

TResourceStream *Resource = new TResourceStream(HInstance, "STUB", RT_RCDATA);
Resource->SaveToFile(Nome);
delete Resource;

HANDLE H = BeginUpdateResource(Nome.c_str(), TRUE);
for(int I = 0; I < ListView1->Items->Count; ++I)
{
TListItem *Item = ListView1->Items->Items;

HANDLE FH = CreateFile(Item->SubItems->Strings[2].c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD Size = GetFileSize(FH, NULL);

BYTE *Buf = new BYTE[Size];

DWORD BR;
ReadFile(FH, Buf, Size, &BR, NULL);

CloseHandle(FH);

UpdateResource(H, RT_RCDATA, (Item->SubItems->Strings[0] + Item->SubItems->Strings[1] + Item->Caption).UpperCase().c_str(), MAKEWORD(LANG_NEUTRAL, SUBLANG_NEUTRAL), Buf, Size);
delete[] Buf;
}
EndUpdateResource(H, FALSE);
 
You probably ought to post at BCBJournal's site since they provided the code.

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top