My objective is to wrap a .exe file in another .exe file. Whenever the wrapper .exe is launched, the embedded .exe should be launched.
I have added the binary file as a resource.
Now I want to load the file as a tmpfile and use the system() function or some alternative to execute the binary file. However, I am not able to get the filename of the tmpfile. I cannot use tmpnam because it will only return a filename but not create an actual temporary file.
My code so far :
#include <iostream>
#include <windows.h>
#include <stdio.h>
using namespace std;
int main()
{
    HRSRC hRes = FindResource(0, MAKEINTRESOURCE(1), RT_RCDATA);
    HGLOBAL hMem = LoadResource(0, hRes);
    void* pMem = LockResource(hMem);
    DWORD size = SizeofResource(0, hRes);
    FILE * f = tmpfile();
    fwrite(pMem, size, 1, f);
    fclose(f);
    return 0;
}
Please do help me. Thank you.