天天看點

VS2017 MFC程式調用C#程式并傳遞多個參數

1、mfc程式中的調用

CString m_param = "chen  chen22";
	ShellExecute(this->m_hWnd, "open", "E:\\chentest\\chentest\\bin\\Debug\\chentest.exe", m_param, "", SW_SHOW);
           

2、C#的啟動程式

namespace chentest
{
    static class Program
    {
        /// <summary>
        /// 應用程式的主入口點。
        /// </summary>
        [STAThread]
          static void Main(string[] Args)
        //static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if(Args.Length==2)
            {
                if((Args[0]=="chen")&& (Args[1] == "chen22"))
                {
                    MessageBox.Show("兩個參數已收到");
                }
            }
           /* for (int intArgIndex = 0; intArgIndex < Args.Length; intArgIndex++)
            {
                // 檢查是否需要輸出日志檔案
                // if (Args[intArgIndex] == "-log")
                //     CommonVar.OutputLog = true;
                if (Args[intArgIndex] == "chen"){
                    MessageBox.Show("收到參數chen1");
                }
                else if (Args[intArgIndex] == "chen22"){
                    MessageBox.Show("收到參數chen22");
                }

                // CommonVar.OutputLog = true;
            }
            */
            
            Application.Run(new Form1());
        }
    }
}
           

 2、兩參數就穿進去了