我試圖從另一個.exe(Windows窗體)運行.exe(Win32)在visual c + +(VS 2012),使用Process::Start
。系統找不到指定的文件(Visual c + +)
因此,我存儲了Windows窗體所在的Win32。我們的想法是:
得到模塊的完全限定路徑:
GetModuleFileName
中刪除文件名和反斜槓從路徑:
PathRemoveFileSpec
添加的Win32應用程序的名稱:
sprintf
傳遞字符串^至
Process::Start
構建沒有錯誤,但在運行失敗時顯示如下圖所示的錯誤。我花了很多時間試圖解決它,但沒有結果。我怎樣才能解決這個問題?
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <string>
#include <cerrno>
#include <Shlwapi.h>
#include <msclr\marshal_cppstd.h>
using namespace std;
using namespace System;
using namespace msclr::interop;
//code...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
TCHAR path[1000];
GetModuleFileName(NULL, path, 1000) ; // path: A pointer to a buffer that receives
// the fully qualified path of the module
PathRemoveFileSpec(path); // path: holds location only (TCHAR)
CHAR mypath[1000];
wcstombs(mypath, path, wcslen(path) + 1); // convert tchar to char (mypath)
// Formatting the string: constructing a string by substituting computed values at various
// places in a constant string
CHAR mypath2[1000];
sprintf(mypath2, "%s\\JoypadCodesApplication.exe", mypath);
String^ result;
result = marshal_as<String^>(mypath2);
Process::Start(result);
}
您是否正在運行64位機器?編輯:在你回答之前,你是否證實路徑實際上是正確的? – Brandon