In my C++ App, which is an .exe, I have this:

int main(int argc, char** argv){
--argc;
++argv;
if (argc != 1){
    throw std::exception("Bad command line.");
}

E.t.c

But how would I call that in my C# (WPF) app? I tried System.Diagnostics.Process.Start("pathofapp.exe", "stringiwantedtouse"), but I got Bad Command Line. What should I do?

有帮助吗?

解决方案

You should try using the c++ program like this:

int main ( int argc, char *argv[] )
{
    if (argc != 1){
        throw std::exception("Bad command line.");
    }
}

And then use argv[0] to access it's first parameter.

For example:

In C++:

int main ( int argc, char *argv[] )
{
    if (argc != 1){
        throw std::exception("Bad command line.");
    }else{
        std::cout << "Param 1: " << argv[0] << std::endl;
    }
}

In C#:

System.Diagnostics.Process.Start("pathofapp.exe", "this");

Output:

Param 1: this

其他提示

System.Diagnostics.Process.Start("pathofapp.exe", "stringiwantedtouse")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top