0
我尝试从imgres32.dll
加载图像。我试图做这样的:C#LoadImage返回错误1813
加载DLL:
dll_h = LoadLibrary(@"C:\Windows\System32\imgres32.dll");
传递句柄到我的功能它执行的ressource加载:
Bitmap b = GetImageResource(dll_h, "1002");
功能如下:
static Bitmap GetImageResource(IntPtr handle, string resourceId)
{
IntPtr img_ptr = NativeMethods.LoadImage(handle, resourceId, IMAGE_BITMAP, 0, 0, 0);
if (img_ptr == IntPtr.Zero)
throw new System.ComponentModel.Win32Exception((int)NativeMethods.GetLastError());
return Image.FromHbitmap(img_ptr);
}
无论哪个参数我进去,我总是得到错误代码1813的意思
在映像文件中找不到指定的资源类型。
当我打开Visual Studio中的文件,我看到一个名为Icon
包含图像的ID 1002
文件夹。
当我点击它,它让我看到几个位图图像包含的,在不同的分辨率,包含一个与16 x 16
分辨率。但是,当我打电话
LoadImage(handle, resourceId, IMAGE_BITMAP, 16, 16, 0);
无论这个没有任何其他的参数组合不工作,我总是得到错误1813
。
IMAGE_BITMAP
是一个常数INT设置为0
像记录here,同样有IMAGE_ICON
和IMAGE_CURSOR
但他们没有工作。
帮助非常感谢。谢谢。
没错。或者,您可以通过将unsigned int传递给本机LoadImage方法而不是字符串来模仿MAKEINTRESOURCE宏:'[DllImport(“user32.dll”,SetLastError = true,CharSet = CharSet.Auto)] public static extern IntPtr LoadImage(IntPtr hinst,uint uId,uint uType,int cxDesired,int cyDesired,uint fuLoad);'然后你可以使用整数1002。 – Yosh