Question

I've written a small console application to wrap a third-party DLL that has issues. I am calling it from a GUI application using _popen, and just want to read a value from the console program's standard output. In doing so, an undesirable console window is briefly displayed.

I am aware that this can be avoided by using a certain STARTUPINFO configuration with CreateProcess. However, I would prefer to put the fix in the console application and still use _popen. Creating the child process using the windows subsystem (i.e. WinMain instead of main) does not make the console window go away. Apparently, a console is allocated by the operating system to facilitate the _popen communication.

Note that the third-party DLL is unstable, but necessary to interface with proprietary hardware. Therefore, any approach the loads the DLL in the GUI applications memory space is unacceptable.

Was it helpful?

Solution

1) I support the idea of launching it with STARTUPINFO set to hide the window. This is SOP on Windows, so it'll work better than trying to impose Unix SOP. Moreover, you may well want to see the output when testing it in isolation.

2) Or you can make a GUI app that doesn't ever show a window. It amounts to a console app without a console.

edit

The link Indeera posted shows how to do the second option.

edit

Ok, if all you want is to send information to the parent, the simplest way is to write a file. One way to keep this orderly is to have the parent pass a unique filename as a command line parameter, which the child writes to. The parent can monitor the file and act on its contents.

There are many alternativers. The closest to the two approaches discussed so far would be named pipes, but you could also use various forms of IPC, including socket-based ones.

What you can't do, however, is access stdin/stdout/stderr without a console. You can launch with a hidden console, but it has to actually have one.

edit

Does lua allow running the executable directly, instead of through cmd.exe?

OTHER TIPS

To communicate between a parent GUI application and a hidden child console application reference the following MSDN articles:

I don't think you can use stdin/stdout without it starting up the console. What you can do though, is write the wrapper app as a GUI app that doesn't show any window (just switch main() to winmain()) and then use some type of IPC mechanism like a socket or shared memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top