我的应用程序中有以下代码:
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int x, int y, int width, int height, uint flags);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hwnd, uint msg,
IntPtr wParam, IntPtr lParam);
我从代码分析 (FxCop) 收到以下警告:
CA1060 : Microsoft.Design : 因为它是 P/Invoke 方法,
'IconHelper.GetWindowLong(IntPtr, int)' 应该在类中定义
命名为 NativeMethods、SafeNativeMethods 或 UnsafeNativeMethods。
有人能告诉我应该把他们分到哪个班级吗?我不知道它是 Native、SafeNative 还是 UnsafeNative。
您可以在此处了解有关此警告的详细信息:http://msdn.microsoft.com/en-us/library/ms182161.aspx http://msdn.microsoft.com/en-us/library/ms182161.aspx。简而言之:
对于大多数应用程序,将 P/Invokes 移至名为 NativeMethods 的新类就足够了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)