[DllImport("user32.dll"))是什么意思? [英] what is meant by [DllImport("user32.dll") ?
本文介绍了[DllImport("user32.dll"))是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我到处搜索,但没有找到[DllImport("user32.dll")]的使用,也不知道如何使用,在哪里使用?
我看到很多具有此属性的代码.我是c#编程的初学者,所以请帮助
hello all
I searched everywhere but i didnt find the use of [DllImport("user32.dll")] and i dont know how to use , where to use ?
i saw lots of codes having this attribute . I am a beginner in programming c# , so please help
推荐答案
这意味着在它下面声明的方法不在.NET中-处于外部(本机) DLL文件.
在这种情况下,它位于User32.dll文件中,该文件是标准Windows组件.
例如:
It means that the method declared below it is not in .NET - it is in a external (native) DLL file.
In this case, it is in the User32.dll file, which is a standard Windows component.
For example:
[DllImport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
SetForegroundWindow方法是Windows的标准功能,上面的声明使我们能够像使用.NET方法一样使用它:
The method SetForegroundWindow is a standard Windows function, and teh above declaration allows us to us it as if it was a .NET method:
public static void SingleInstance(this Process thisProcess)
{
foreach (Process proc in Process.GetProcessesByName(thisProcess.ProcessName))
{
if (proc.Id != thisProcess.Id)
{
ShowWindow(proc.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(proc.MainWindowHandle);
thisProcess.Kill();
}
}
}
您没有到处搜索,否则您会发现 ^ ].
You did not search everywhere, otherwise you would have found this[^].
^ ]可能还会为您提供更多信息.
This[^] might also give you extra information.
这篇关于[DllImport("user32.dll"))是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文