Home > Enterprise >  How to get Handle of a created Process in Unreal Engine 4?
How to get Handle of a created Process in Unreal Engine 4?

Time:04-08

I am using PlatformProcess::CreateProc() to create a Process. It seems to return an FProcHandle. How do I get its HWND?

CodePudding user response:

An HWND is a window handle, but CreateProc() creates a process, so you probably want a process handle (HANDLE) instead.

The FProcHandle returned by CreateProc() has a void* Handle member, which you should be able to type-cast to HANDLE. Or, you can try passing the FProcHandle::OpenedPid or FProcHandle::ProcInfo->ProcessId member to the Win32 OpenProcess() function.

If, on the other hand, you really want a window handle, ie if you want to find a window that the launched process creates for itself (preferably after a delay to give the process time to create the window), then you can use the Win32 API WaitForInputIdle(), EnumWindows(), and GetWindowThreadProcessId() functions to search for any windows that belong to the same process ID reported by the FProcHandle.

CodePudding user response:

Another option is a bit more complicated: you can hook window creation using SetWindowsHookEx and implement CBTProc callback function.

There is a code example that also shows how to get a class name for those created windows: Hooking for create window and want to get class name

You can figure out the class name for your Unreal Engine 4 app, set up that hook before calling CreateProc() and wait for it to be created.

  • Related