When the project is relatively large, it is usually developed separately. If the separate part is only some functions or classes, static or dynamic libraries can be used for integration. However, if an EXE file is separated, it must be used by calling the EXE file during integration. This is especially required when a third-party software is an EXE file written in C language.
I recently encountered this problem in the LCDs system I developed. He needs to call a classifier to process data, while the classifier at hand is a classic C4.5 decision tree classifier, which is written in C language and does not. the H header file generates an EXE file and processes the data by executing the main function on the command line. If you want to change it to a static or dynamic library, it seems difficult to call its function after rewriting because there is no header file, so you should directly call the generated EXE file. You can consider the following methods:
1. Use System Function 2. Use execl or execv function 3. Use winexec function 4. Use CreateProcess function 5. Use shellexecuteex Function
System functions, execl functions, and execv functions do not control whether the program window is displayed. The result I want is that the EXE program window is not displayed. Therefore, these two methods are not considered. The winexec function is difficult to control the main program to wait for the end of the EXE program, so give up. The CreateProcess function is used to create a new process. Therefore, you must manually control the life and death of the process. It is not as convenient as shellexecuteex. Therefore, I chose the shellexecuteex function. The procedure is as follows:
Shellexecuteinfo shexecinfo = {0 };
Shexecinfo. cbsize = sizeof (shellexecuteinfo );
Shexecinfo. fmask = see_mask_nocloseprocess;
Shexecinfo. hwnd = NULL;
Shexecinfo. lpverb = _ T ("open ");
Shexecinfo. lpfile = _ T ("c4.5.exe ");
Shexecinfo. lpparameters = _ T ("-F train ");
Shexecinfo. lpdirectory = NULL;
Shexecinfo. nshow = sw_hide;
Shexecinfo. hinstapp = NULL;
Shellexecuteex (& shexecinfo );
Waitcursorbegin ();
Waitforsingleobject (shexecinfo. hprocess, infinite );
Waitcursorend ();