我正在使用Visual Studio 2012的代码分析工具时遇到了这个警告。代码如下:
using System;
using System.Runtime.InteropServices;
namespace MyProgramNamespace
{
class NativeMethods
{
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
public static extern IntPtr GetWindowLongPtr(IntPtr handle, int flag);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
public static extern IntPtr SetWindowLongPtr(IntPtr handle, int flag, IntPtr ownerHandle);
}
}
我只编译x64,所以我不关心使用旧的GetWindowLong和SetWindowLong。就我所知,这些入口点名称是正确的。
编辑:已解决。 原来问题是Visual Studio本身(因此Code Analysis工具)是32位的。当代码分析工具检查user32.dll以查看这些函数是否存在时,它会检查32位版本的user32.dll (在C:/Windows/SysWOW64/中),而不是程序实际使用的版本(64位版本在C:/Windows/System32中),而且这些函数仅存在于64位版本中(32位版本使用GetWindowLong/SetWindowLong代替GetWindowLongPtr/SetWindowLongPtr(请注意PTR部分))。