PInvokeStackImbalance同时使用"静态外部INT系统(字符串str)Q​​UOT; [英] PInvokeStackImbalance while using "static extern int system(string str)"

查看:103
本文介绍了PInvokeStackImbalance同时使用"静态外部INT系统(字符串str)Q​​UOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用系统(字符串str)命令在C#DOS的操作。

I'm trying to use the system(string str) Command for dos-operations in C#.

namespace XYZ
{
    internal class Program
    {
        [DllImport("msvcrt.dll")]
        static extern int system(string str);

        static void Main(string[] args)
        {
             string Command = Console.ReadLine();
             system(Command); 
             /* Excutes command, then "PInvokeStackImbalance". */
        }
    }
}



我知道使用静态外部INT系统(字符串str)是一个糟糕的解决方案,但我已经尝试过其他的解决方案,没有工作。

I know using static extern int system(string str) is a bad solution, but I've tried other solutions which did not work.

推荐答案

您忘了指定的调用约定:

You forgot to specify the calling convention:

[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int system(string str);



我通常试图解释为什么,但这里似乎没有必要;)这是否则不太可能解决您的问题,不管它可能是,它是一回事

I normally try to explain why but that seems unnecessary here ;) This is otherwise unlikely to fix your problem, whatever it may be, it is the same thing as

Process.Start("cmd.exe", "/c " + str);

这篇关于PInvokeStackImbalance同时使用"静态外部INT系统(字符串str)Q​​UOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆