Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Load or Extract Bitmap and Images in DLL file (Like : imageres.dll in windows 7) in VB.NET 8.0 or VB.NET 9.0?
Posted
Updated 30-Sep-11 3:14am
v3

1 solution

From How to extract bitmap from a windows resource file[^]:
I did it a while ago in VB.Net, and it took hours of work.

If it is for any file, then you will need to find out what resource types there are, then for each type what resources exist of that type - resources are either named in a string or have an integer Id (both stored in a pointer). Then, you'll need to check if there are multiple language versions of each named resource. Then, you can finally get at the resources. For bitmaps, there probably aren't multi-language versions, though I guess it is possible.

Resource reference in the MSDN starts here: Introduction to Resources[^]

EnumResourceTypes - Lets you find out what resource types are in the file
EnumResourceNames - find the resource names of resources of a given type.
EnumResourceLanguages - find the languages available given a resource name and resource type.

So, as mentioned, you would use LoadLibrary to get a handle to the module in question (SafeFileHandle). Then enumerate the available types to check there are bitmaps. Then enumerate the names of the bitmap resources. Then maybe check to ensure there aren't multiple language versions of the bitmaps. Then you could use LoadImage to load a bitmap by name (assuming there aren't multiple language versions, because LoadImage doesn't accept a language), copy the bitmap, and destroy the native handle with DeleteObject.

Once you have altered the bitmap, you do as described by kaymaf to UpdateResources.

I found that the hard part was dealing with the name and type values of the resources. If the resource is an INTRESOURCE then all it's bits except the last 16 are 0. If so treat is as a number. Otherwise it's a pointer to a string. So - get them as IntPtr, test them and either store a string (Marshal.PtrToStringAuto) or a number. Then when you use them again, you will need overloads of the functions to take IntPtr or String.

And .. no, I don't have code to share.

An alternative would be to use resource hacker in CommandLine mode, which I guess could be done from VB.Net.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900