How do I convert from a Cursor to an image that can be saved into an .resx file using C#?
I am trying to read a cursor image from a dll file complied in Visual Basic. So far, the program can pull out strings and bitmaps just fine, but it does not like pulling out cursors. After pulling out the resources, the program then saves them in a .resx file instead of a dll. I am having some trouble because I don't think that .resx files support cursors directly.
Here is what I have so far:
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, uint lpCursorName);
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
var Lib = LoadLibrary("myLib.dll");
IntPtr cRes = LoadCursor(Lib,101);
Cursor c = new Cursor(cRes);
writer.AddResource("cursor_" + 101, c);
This works perfectly on other files, but when I try to do this with cursors, it throws an "InvalidOperationException" and says the image format is not valid. It actually loads the handle into Cursor no problem, but will throw the exception when I try to save it as a .resx. I've tried loading the cursor as a bitmap instead, but that just loads a blank image. CursorConverter doe开发者_开发知识库sn't appear to work for images either.
So if anyone has any ideas on how to work this out, please let me know. Thank you!
The documentation for LoadCursor says it has been superseded by LoadImage. Have you tried using that?
精彩评论