PInvokeStackImbalancewhenusing"staticexternintsystem(stringstr)".命名空间XYZ{内部类程序{[DllImport("msvcrt.dll")]staticexternintsystem(stringstr);staticvoidMain(string[]args){stringCommand=Console.ReadLine();系统(命令);/*执行命令,然后执行“PInvokeStackImbalance”。*/}}}我知道使用staticexternintsystem(stringstr)是一个糟糕的解决方案,但我已经尝试过其他无效的解决方案。您忘记指定调用约定:[DllImport("msvcrt.dll",CallingConvention=CallingConvention.Cdecl)]staticexternintsystem(stringstr);我通常会尝试解释原因,但这似乎没有必要;)否则可能无法解决您的问题,无论它是什么,它都是相同的Process.Start("cmd.exe","/c"+str);一般来说,你做错了。此函数旨在用于基于C/C++本机控制台的应用程序。在C#中,您拥有System.Diagnostic命名空间,您可以轻松地使用它来启动新进程。请参阅此处:C#中的C#"system()"当然您也可以使用该函数。调用异常可能是因为DllImport短语不完整,请参见.Net4:PInvokeStackImbalanceexception此线程是关于strlen的,但我几乎可以肯定system()和strlen()使用相同的堆栈约定。以上就是C#学习教程:PInvokeStackImbalancewhenusing"staticexternintsystem(stringstr)"的全部内容,不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
