Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 平台pinvoke教程msdn_C#_Pinvoke - Fatal编程技术网

C# 平台pinvoke教程msdn

C# 平台pinvoke教程msdn,c#,pinvoke,C#,Pinvoke,以下是来自的教程。_flushall的输出在教程中是“Test”,但我通过使用console.write()显示输出得到了“2”。有人能解释一下吗 using System; using System.Runtime.InteropServices; class PlatformInvokeTest { [DllImport("msvcrt.dll")] public static extern int puts(string c); [DllImport("msvcr

以下是来自的教程。_flushall的输出在教程中是“Test”,但我通过使用console.write()显示输出得到了“2”。有人能解释一下吗

using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
    [DllImport("msvcrt.dll")]
    public static extern int puts(string c);
    [DllImport("msvcrt.dll")]
    internal static extern int _flushall();

    public static void Main() 
    {
        puts("Test");
        _flushall();
    }
}

这些代码在现代Windows版本上不再有效。您得到的“msvcrt.dll”版本是一个用于Windows可执行文件的专用CRT实现,它以其他无法诊断的方式进行了修补,可能与安全性有关

你需要另找一个仍然友好的。如果安装了Visual Studio 2010或更高版本,您的计算机上将会有一个。请查看c:\windows\syswow64目录,并查找msvcrxxx.dll,其中xxx为100、110或120。相应地更改声明。在我的机器上,安装了VS2013:

[DllImport("msvcr120.dll")]
public static extern int puts(string c);
[DllImport("msvcr120.dll")]
internal static extern int _flushall();
输出:

试验


从for _flushAll,该方法返回开放流的数量。此外,_flushAll的返回类型应为int。因此,它不能为“测试”。但是,上面程序的输出是“Test”,因为它是通过调用put方法打印的。True返回类型是int。那么如何获取值“Test”呢?如果我正确理解您的注释,则“Test”是通过调用put方法打印到控制台的。您能显示吗?