以下是msdn的教程._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();
}
}
Run Code Online (Sandbox Code Playgroud)
该代码在现代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();
Run Code Online (Sandbox Code Playgroud)
输出:
测试
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |