问题
I try to load an image from imgres32.dll
. I'm trying to do it like this:
Load the dll:
dll_h = LoadLibrary(@"C:\Windows\System32\imgres32.dll");
Pass the handle to my function which does the ressource loading:
Bitmap b = GetImageResource(dll_h, "1002");
The function looks like this:
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);
}
No matter which parameters I enter, I always get error code 1813 meaning
The specified resource type cannot be found in the image file.
When I open the file in Visual Studio, I see a folder called Icon
containing an Image with id 1002
.
When I click it, it shows me several Bitmap images contained, in different resolutions, containing one with resolution 16 x 16
. But when I call
LoadImage(handle, resourceId, IMAGE_BITMAP, 16, 16, 0);
Neither this not any other parameter combination does work, I always get error 1813
.
IMAGE_BITMAP
is a constant int set to 0
like documented here, same with IMAGE_ICON
and IMAGE_CURSOR
but none of them works.
Help is very much appreciated. Thanks.
回答1:
You should prefix the resource Id with #. Call it this way:
GetImageResource(dll_h, "#1002");
来源:https://stackoverflow.com/questions/39507459/c-sharp-loadimage-returns-error-1813