调用外部exe传递参数 接受参数

最近开发一个Activex控件,需要调用外部exe(接受多个参数),并且传递多个参数。

这里主要介绍调用外部exe传递参数和exe接受参数。

调用外部exe的几种方法具体用法请参考:

http://blog.163.com/laowu_000/blog/static/47198890201042021747662/

http://blog.csdn.net/moyumoyu/article/details/6767621

我用到的是WinExec()函数。

1.如果仅仅是调用外部exe文件打开一个文件,调用方法:WinExec("调用的.exe  要打开的.txt",1),中间用空格隔开,外部exe中不需要写接受函数。

2.调用外部exe并传递多个参数

  调用方法:WinExec("调用的.exe 参数1 参数2 参数3",1),多个参数中间用空格或其他分隔符隔开。

    exe接受参数:

CString szCmd = AfxGetApp()->m_lpCmdLine; //szCmd 接收到的字符串是 :参数1 参数2 参数3

CStringArray str;

int nSize = splitString(szCmd, ' ', str );//分割字符串

for(int i=0;i<nSize ;i++){
   str.GetAt(i);//各个参数
}

int splitString(CString str, char split, CStringArray& strArray)
{
    strArray.RemoveAll();

    CString strTemp = str;    //此赋值不能少
    int nIndex = 0; //
    while( 1 )
    {
        nIndex = strTemp.Find(split);
        if( nIndex >= 0 )
        {
            strArray.Add( strTemp.Left( nIndex ) );
            strTemp = strTemp.Right( strTemp.GetLength() - nIndex - 1 );
        }
        else break;
    }
    strArray.Add( strTemp );
       return strArray.GetSize();
}                       
原文地址:https://www.cnblogs.com/xsgame/p/3070575.html