0

This post put me on the track of loading an exe from a resource, but I haven't been able to find out how to start running the executable after LockResource.

Do I need to use the memory address returned from LockResource, and then run it somehow like that?

I will be loading a SUBSYSTEM:CONSOLE program into a SUBSYSTEM:SYSTEM program in my end program, but I would like to know the more basic way of two SUBSYSTEM:CONSOLE programs, as the knowledge will be useful anyway.

Code:

#include <windows.h>
#include <iostream>
#include "resource.h"

HGLOBAL hResLoad;   // handle to loaded resource
HRSRC hRes;         // handle/ptr. to res. info. in hExe
LPVOID lpResLock;   // pointer to resource data

int main() {
    hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_MYFILE), RT_RCDATA);
    hResLoad = LoadResource(hExe, hRes);
    lpResLock = LockResource(hResLoad);
}

Thanks in advance.

clouded.
  • 15
  • 6
  • Allocate some virtual memory with read/write/execute permissions and copy the resource into it. You might be able to do this with the address return by `LockResource` but this memory is owned by the resource API and doing things with the memory's access right may break things. – Richard Critten Apr 18 '23 at 22:44
  • It there a way I could use `CreateProcess`, maybe by exporting the exe to its own file, then running it with `CreateProcess`? – clouded. Apr 18 '23 at 22:48
  • I have found the way to do it. Check out [this post.](https://stackoverflow.com/a/60711405/20000421) – clouded. Apr 19 '23 at 02:32
  • Hi ,glad to know you've found the solution to resolve this issue! Since the reply in the link was not accepted as an answer, consider turning your solution into an answer and mark it as the accepted answer. It will also help others to solve the similar issue. – Minxin Yu - MSFT Apr 21 '23 at 05:43

0 Answers0