error extracting resource from EXE file

Hello i'm trying to extract one Exe file using windows Api and Qt like framework. But ever extract me my file and show me again new error's again. The code is the follow:
.pro file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
QT += core
QT -= gui

CONFIG += c++11

TARGET = untitled6
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

RC_FILE += resources.rc

HEADERS += \
    resource.h

resource.h:
1
2
3
4
5
6
#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED

#define ELEXE "ELEXE"

#endif // RESOURCE_H_INCLUDED 


resource.rc:
1
2
3
4
#include <windows.h>
#include "resource.h"

ELEXE RCDATA "C:/Users/MyUser/Desktop/application.exe"


main.cpp:
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();
}

error's:
https://i.stack.imgur.com/YY59s.png

some know or help me to solve this issue? Thanks in advance.
Last edited on
Topic archived. No new replies allowed.