0

Is there any possibility of capturing opengl output of child process?

Child should not have a different window. Output should be captured and displayed by parent instead.

I know that i can create a layer that my child could use to create opengl callbacks in my parent application. And send data by socket or pipe.

Edit: I write main and child applications.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1
    Are you writing both parent and child or does the child application already exist and not designed to cooperate in this way? – Ben Voigt Mar 01 '22 at 22:47
  • 1
    Does [this](https://stackoverflow.com/questions/5559366/is-it-possible-to-draw-on-hwnd-created-by-another-process) help? But I don't know what you mean by 'capture'. – Paul Sanders Mar 01 '22 at 22:52
  • Yes it is somewhat helpful. I write both parent and child applications. But I need to reload some DLLs on the fly with user code. As i don't want to close my main app. One idea was to create child app that will be executed and closed when main app want to. And then get input output to from child app. And display contents in main app. – Michał Marszałek Mar 01 '22 at 22:56

1 Answers1

0

OK, here's a rundown of how I think this can be done. This is totally untested, so YMMV.

  1. Create your window in the parent process. According to this page, you need to create it with the CS_OWNDC style, which means it has the same HDC permanently associated with it.

  2. Launch your child process. You can pass the HWND to it as a command line parameter, converted to hex-ascii, say, or you can devise some other method.

  3. In the child process, call GetDC to retrieve the HDC of the parent's window and pass it to wglCreateContext (I imagine you know all about doing that sort of thing).

  4. In the child process, draw, draw, draw.

  5. Before exiting the child process, make sure you call ReleaseDC to free up any resources allocated by GetDC.

This ought to work. I know that Chrome uses a separate process for each browser tab, for example (so that if the code rendering into any particular tab should crash, it affects that tab only).


Also, if you're thinking of jumping through all these hoops just because you want to reload some (different) DLLs, maybe you're looking for LoadLibrary and GetProcAddress instead. Hmmm, maybe I didn't need to write all that :)

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48
  • This is c++. Create object from dll. And then free DLL. Segfault – Michał Marszałek Mar 01 '22 at 23:20
  • Create what object? Whatever it is, shouldn't you tell the DLL to destroy it before you unload it? Or don't you control the DLL? – Paul Sanders Mar 01 '22 at 23:39
  • Example object of class declared in dll. But this class is child of another class. This pointer is given to app. And it works. There are some problems like extern c some casting to shared pointer. And it must be the same compiler... And now i free DLL. Dll code is unloaded. Static variables destroyed. But wait i have in my app object created in dll. I should delete it. (Smart pointer release). But i forgotten to do this. Now i call virtual function from my code for this object. And i have now asm call to memory address that I don't own. – Michał Marszałek Mar 02 '22 at 14:24
  • Looks like you need to pay more attention to object lifetimes. Worth doing anyway I would think, it pays to get it right. – Paul Sanders Mar 02 '22 at 15:19