Tag: msvcrt

in .Net 4:PInvokeStackImbalanceexception

我在.Net 3.5项目中使用了msvcrt.dll中的strlen函数。 进一步来说: private unsafe static extern int strlen( byte *pByte ); 迁移到.NET 4.0后,如果我使用此函数,则会抛出PInvokeStackImbalanceexception。 如何导入.NET 3.5 msvcrt.dll或修复此exception?

使用“static extern int system(string str)”时的PInvokeStackImbalance

我正在尝试在C#中使用系统(string str)命令进行dos操作。 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”. */ } } } 我知道使用static extern int system(string str)是一个糟糕的解决方案,但我尝试过其他无效的解决方案。