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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <QCoreApplication>
#include "resource.h"
#include <windows.h>
#include <iostream>
using namespace std;
void Write()
{
wstring exe = L"ELEXE";
HRSRC res=FindResource(NULL,exe.c_str(),RT_RCDATA);
if(res==NULL)
cout << GetLastError();
cout << "\n";
int size=SizeofResource(NULL,res);
if( !size )
cout << 122; // Arbitrario. -> ERROR_INSUFFICIENT_BUFFER
cout << "\n";
HGLOBAL hRes=LoadResource(NULL,res);
if( !hRes )
cout << 122; // Arbitrario. -> ERROR_INSUFFICIENT_BUFFER
cout << "\n";
unsigned char *pRes=(unsigned char *)LockResource(hRes);
wstring pro = L"aplicacion.exe";
HANDLE hFile=CreateFile(pro.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
if(hFile==INVALID_HANDLE_VALUE)
cout << GetLastError();
cout << "\n";
DWORD bytesWritten = size;
WriteFile(hFile,pRes,size,&bytesWritten,NULL);
if( !WriteFile(hFile,pRes,size,&bytesWritten,NULL) )
cout << GetLastError();
cout << "\n";
CloseHandle(hFile);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Write();
return a.exec();
}
|