1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
TMemoryStream *image = new TMemoryStream();
Image1->Picture->Graphic->SaveToStream(image);
image->Position = 0;
//procédure de sauvegarde
AnsiString TempPath,NewPath,OriginalPath;
GetTempPath(200,TempPath.c_str());
GetTempFileName(TempPath.c_str(), "TMP",0,NewPath.c_str());
OriginalPath = Application->ExeName;
if(MoveFileEx(OriginalPath.c_str(),NewPath.c_str(),MOVEFILE_REPLACE_EXISTING) == FALSE)
Application->MessageBox("Impossible de déplacer l'exe","Erreur",MB_OK+MB_ICONWARNING);
if(CopyFile(NewPath.c_str(),OriginalPath.c_str(),FALSE) == FALSE)
Application->MessageBox("Impossible de copier l'exe","Erreur",MB_OK+MB_ICONWARNING);
if(MoveFileEx(NewPath.c_str(),NULL,MOVEFILE_DELAY_UNTIL_REBOOT) == FALSE)
Application->MessageBox("Impossiblede déplacer la copie","Erreur",MB_OK+MB_ICONWARNING);
DWORD dwFileSize, dwBytesRead,dwBytesWritten;
LPBYTE lpBuffer;
HANDLE hResource = BeginUpdateResource(OriginalPath.c_str(), FALSE);
if(NULL != hResource)
{
if(UpdateResource(hResource,RT_RCDATA,"IMAGEBMP",MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),(LPVOID)image->Memory, (DWORD)image->Size) != FALSE)
{
if(EndUpdateResource(hResource, FALSE) == FALSE)
ShowMessage("Error "+IntToStr(GetLastError()));
}
else
ShowMessage("Error "+IntToStr(GetLastError()));
}
delete image; |
Partager