我成功运行:
Process::Start("C:\\Users\\Demetres\\Desktop\\JoypadCodesApplication.exe");
来自Windows窗体应用程序(visual c ++),正如预期的那样,我有2个程序同时运行。我的问题是:
我可以将表示文件名的字符串传递给Process::Start
方法吗?我试过了:
std::string str="C:\\Users\\Demetres\\Desktop\\JoypadCodesApplication.exe";
Process::Start("%s", str);
但失败了。这可能吗?
修改
答案 0 :(得分:1)
Process::Start
需要String^
,并且您尝试将其传递给std::string
。它没有variadric版本,也不知道std::string
是什么。要传递std::string
的值,您必须整理它:
std::string str("Some Path");
Process::Start(marshal_as<String^>(str));
答案 1 :(得分:1)
我认为你实际上需要为System::String^
编组以传递参数。
您甚至可以直接从std::string
封送到System::String^
。
///marshal_as<type>(to_marshal)
///marshal_context ctx; ctx.marshal_as<const char *>(to_marshal)
#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>
#include <msclr/marshal_atl.h>
using namespace msclr::interop;
using namespace System::Runtime::InteropServices;
Process::Start(marshal_as<String^>(str));
但在这种情况下,您只需使用String^
:
String^ str = L"path to file";
Process::Start(str);
当您使用C ++ / CLI时,您需要来回编组或从一开始就使用正确的数据类型来使用它。