Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Borito30 en 12 Febrero 2017, 21:34 pm



Título: Solucionar estos errores en las funciones de window
Publicado por: Borito30 en 12 Febrero 2017, 21:34 pm
He hecho un pequeño programa en el que hago uso de las funciones  de windows el codigo es el siguiente.

resources.rc:

Código:
#include <windows.h>
#include "resource.h"

ELEXE RCDATA "Example1.exe"

resource.h:

Código:
#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED

#define ELEXE ""

#endif // RESOURCE_H_INCLUDED

main.cpp:

Código:
#include <iostream>
#include <windows.h>
#include "resource.h"

using namespace std;

int main()
{

    string exe = "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);


    HANDLE hFile=CreateFile("C:/Users/android/Desktop/pi.exe",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);


    ShellExecute(HWND_DESKTOP,NULL,"C:/Users/android/Desktop/pi.exe",NULL,NULL,SW_SHOWNORMAL);
    system("pause");
    return 0;
}

El problema esta en que me devuelve los siguientes errores:

(https://i.stack.imgur.com/xBrlv.png)

tanto res como size como hres me devuelven error por qué?