I came across a C++ program for my use, in which there was some processing being done using some files and exes. Inside my C++ program, I had a snippet like
system(exe1 exe2 > TestFile1.txt exe3 > TestFile2.txt)
system(exe2 exe3 > TestFile3.txt exe3 > TestFile4.txt)
system(exe3 exe2 > TestFile5.txt exe3 > TestFile6.txt)
system(exe4 exe1 > TestFile7.txt exe3 > TestFile8.txt)
Now, I generated a .dll out of this C++ program to use in my C# app through P/Ivoke (Dllimport) but since the C++ had these system being used, it fires different processes and new cmd windows when I use this .dll in my C# program.
I thought to get rid of this by generating the dll’s of all the exes (exe1, exe2, exe3 etc.) and firing the main function from these dlls, but it doesn’t strike to me about how will I do that in C++ program?
I can export the main function from the C++ (exe1 dll, exe2 dll, exe3 dll etc.) and call it through C# P/Invoke, but I want an alternative like this for C++. to replace the above 4 line snippet. How can that be done?
You can start processes (also those which operate in text mode) without them having opening a console window. Please don’t bolt me down on the details, since it’s been ages since I’ve done this the last time (on Windows, I do it on regular terms on *nix systems). What I can tell you is, that you have to look into the function
CreateProcessEx. You’ll also have to reimplement the redirection of stdout into those textfiles.I strongly advise against putting those processes into DLLs because then they’ll run into your main process address space and will mess things up (BTW: You can load EXEs as if they were DLLs, but calling their entry function will b0rk your main process, so don’t do it).