Calling the EXE executable file in the C ++ Program

Source: Internet
Author: User

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. Especially when third-party software isC LanguageThis is especially required when compiling an EXE file.

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 and execl and execv functions cannot be controlledProgramWhether the window is displayed. The result I want is that the window of the EXE program is not displayed, so 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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.