我是 Win32 API 的新手。我正在尝试使用 win32 API。当我加载图像时,我得到了一个句柄,但我也得到了 GetLastError 响应 0x06,无效句柄。我究竟做错了什么?
class Program
{
[DllImport("user32.dll", EntryPoint="LoadImage", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
int cxDesired, int cyDesired, uint fuLoad);
[DllImport("kernel32.dll", EntryPoint ="GetLastError", CallingConvention = CallingConvention.StdCall)]
public static extern uint GetLastError();
static void Main(string[] args)
{
string path = @"c:\temp\bitmap.bmp";
IntPtr pointer = LoadImage(IntPtr.Zero, path, 0, 256, 256, 0x00008010);
uint result = GetLastError();
Console.WriteLine(pointer);
Console.WriteLine(result);
Console.ReadLine();
}
}
输出内容为:
-1576718263
6
我不确定我做错了什么。我想配置调用以从文件加载图像,并且还具有共享句柄,因为我将通过应用程序使用该句柄。
谢谢, Maciej