简体   繁体   English

是否可以直接使用Microsoft.Win32命名空间中的Win32Native类?

[英]Is it possible to directly use the Win32Native class from the Microsoft.Win32 namespace?

Is there any way to directly use the Win32Native namespace? 有没有办法直接使用Win32Native命名空间?

I would like to directly call the method: 我想直接调用方法:

Win32Native.SendMessageTimeout(new IntPtr(0xffff), 0x1a, IntPtr.Zero, "Environment", 0, 0x3e8, IntPtr.Zero) == IntPtr.Zero;    

as opposed to declaring it: 而不是宣布它:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);

Is there any chance of that? 那有什么机会吗?

I assume you mean the Microsoft.Win32.Win32Native class. 我假设你的意思是Microsoft.Win32.Win32Native类。 No, you cannot call it, it is internal. 不,你不能叫它,它是内部的。 You could probably do something with reflection, but that would be even uglier. 你可以用反射来做一些事情,但那会更加丑陋。

Microsoft could change the API at any time; Microsoft可以随时更改API; via a new Framework version, service pack, etc. Since it is internal, they have no obligation to support it even if they make a change that breaks your application if you were directly calling it. 通过新的框架版本,服务包等。由于它是内部的,即使他们在您直接调用它时进行了破坏您的应用程序的更改,他们也没有义务支持它。

In short: write the platform invoke yourself. 简而言之:自己编写平台调用。

You should also look at http://pinvoke.net/ . 您还应该查看http://pinvoke.net/ This site contains many platform invoke signatures already defined for you. 此站点包含许多已为您定义的平台调用签名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM