前言
在开发项目的时候,有的时候需要调用外部exe文件。那么在C/C++里面直接调用exe文件的方法有哪些呢?现在可考虑的方法主要有:
使用system函数使用execl或者execv函数使用WinExec函数使用CreateProcess函数使用ShellExcecuteEx函数
这里,我们用作测试的exe文件为:sleepXs.exe,此exe会将输入参数(int形)加起来并返回,程序在执行时会休眠X秒,X由用户从外部动态定义。程序源码如下:
#include
#include
using namespace std;
int main(int argc, char* argv[]){
int c=0;
if(argc>1){
for(int i=1;i
c+=atoi(argv[i]);
}
}
int time;
cout<<"- - 请输入延时时间(s):"<
cin>>time;
cout<<"- - sleep "<