I'm new to Win32 API. I'm trying use the win32 API. When I load an image I get a handle back, but I also get GetLastError response 0x06, invalid handle. What am I doing wrong?
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();
}
}
The output reads i.e.:
-1576718263
6
I'm not sure what I'm doing wrong. I wanted to configure the call to load the image from file, and also have shared handle as I'll be using that handle though the application.
Thanks, Maciej