C Sharp中的本机方法 [英] native methods in c sharp

查看:99
本文介绍了C Sharp中的本机方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.有人知道如何在c Sharp中使用NativeMethods吗?它有特殊的名称空间吗?

Hi. Does anybody know how to use NativeMethods in c sharp? Does it have special namespace?

推荐答案

您可能是在用NativeMethods一词来谈论WinApi方法. 如果是这样,则必须期待在.NET环境中使用P/Invoke.

例如,可以以以下格式声明从User32.dll调用方法GetDC的方法:

You probably talking about WinApi methods in meaning of word NativeMethods.
If it''s true, you must look forward to use P/Invoke in .NET enviroment.

For example calling of method GetDC from User32.dll could be declared in next format:

[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);



仔细查看 P \调用
祝您好运.



Take a closer look to P\Invoke
Good luck.


除了Oleksandr的回答外,将P \ Invoke方法包装在一个名为"NativeMethods"的类中是一种惯例,因此,如果您要查找特定的类使用这个名称,我建议您查看可能在其中引用过代码的任何外部库(通过键入方式进行猜测,可能是这种情况).
In addition to Oleksandr''s answer, wrapping P\Invoke methods in a class called "NativeMethods" is a convention, so if you''re looking for a specific class with that name I suggest looking into any external libraries used with code where you may have seen it referenced (making a guess from how you typed it that this may be the case).


这篇关于C Sharp中的本机方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆