// Sample3_CreateProcessFromMemory.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <shellapi.h>

#include "..\\..\\..\\..\\BoxedAppSDK\\include\\BoxedAppSDK.h"
#pragma comment(lib, "..\\..\\..\\..\\BoxedAppSDK\\lib\\BoxedAppSDK.lib")

int _tmain(int argc, _TCHAR* argv[])
{
	BoxedAppSDK_Init();

	HMODULE hModule = GetModuleHandle(NULL);
    HRSRC hResInfo = FindResource(hModule, _T("BIN1"), _T("BIN"));
    HGLOBAL hResData = LoadResource(hModule, hResInfo);
    LPVOID lpData = LockResource(hResData);
    DWORD dwSize = SizeofResource(hModule, hResInfo);

	HANDLE hFile = BoxedAppSDK_CreateVirtualFile(_T("app1.exe"), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, 0, NULL);
	DWORD temp;
	WriteFile(hFile, lpData, dwSize, &temp, NULL);
	CloseHandle(hFile);

	WinExec("app1.exe", SW_SHOW);

	printf("Press Ctrl + C to finish");

	Sleep(-1);

	return 0;
}
