平台pinvoke教程msdn
以下是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(); } }
该代码在现代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();
输出:
测试
上述就是C#学习教程:平台pinvoke教程msdn分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/949479.html