I have added an .ICO icon image to a .NET WinForms program using the Resources page in the projects options. Is it possible to access this resource using Windows API functions like LoadImage, ideally by specifying a resource ID (in native code done using the MAKEINTRESOURCE macro if the icon is referenced in the .RC resource file)? Or is it necessary to load the icon resource using .NET framework methods and to afterwards provide the icon handle to the API function?
1 Answers
Here is my Github repository with my latest iteration of my Windows Desktop toolkit, named DataTools.
It is written in VB.NET but at its core there is some pure CIL coding so it's very fast.
The library can be included in either VB or C# projects for use in the Windows Desktop environment.
It includes MemPtr, which is a drop-in replacement for IntPtr.
Since you are very interested in grabbing resources from EXE files, look at the DTInterop project, specifically DataTools.Interop.Desktop.Resources.
I spent a great many years on this entire project. It's clean, it holds together well, and the VB is easily translatable to C#; that the interop methodology is still the same.
I did a lot of homework and listened to a lot of ancient Windows gurus, along the way, most of whom have their home in the straight-C language Win32 API of legend and old.
My code is heavily commented and documented, so you shouldn't have any problem figuring out which way is up.
Assembly.LoadFile()
), then use theAssembly.GetManifestResourceNames()
method to extract any the.resource
parts and useAssembly.GetManifestResourceStream()
to save it (disc or MemoryStream). Finally, use the ResourceReader class to extract any of the resources contained in any of the.resource
parts that the loaded Assembly contains. No API required. – Jimi