在DLL文件中加载位图和图像 [英] Loading Bitmaps and Images in DLL files

查看:110
本文介绍了在DLL文件中加载位图和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在VB.NET 8.0或VB.NET 9.0中的DLL文件(例如Windows 7中的imageres.dll)中加载或提取位图和图像?

解决方案

<从如何从Windows资源中提取位图文件 [ ^ ]:

我前一阵子是在VB.Net中完成的,它花了数小时的时间.

如果用于任何文件,则需要找出存在的资源类型,然后针对每种类型找出存在该类型的资源-资源要么以字符串命名,要么具有整数ID(均存储在指针中) .然后,您需要检查每个命名资源是否有多种语言版本.然后,您终于可以获取资源了.对于位图,可能没有多语言版本,尽管我想这是可能的.

MSDN中的资源参考从此处开始:资源简介 [ ^ ]

EnumResourceTypes-让您找出文件中有哪些资源类型
EnumResourceNames-查找给定类型的资源的资源名称.
EnumResourceLanguages-查找在给定资源名称和资源类型的情况下可用的语言.

因此,如前所述,您将使用LoadLibrary获取有关模块的句柄(SafeFileHandle).然后枚举可用的类型以检查是否有位图.然后枚举位图资源的名称.然后可能要检查以确保位图没有多种语言版本.然后,您可以使用LoadImage按名称加载位图(假设没有多种语言版本,因为LoadImage不接受一种语言),复制位图,并使用DeleteObject销毁本机句柄.

更改位图后,请按照kaymaf的说明执行UpdateResources.

我发现最困难的部分是处理资源的名称和类型值.如果资源是INTRESOURCE,则除后16个位以外的所有位均为0.如果是这样,则将其视为一个数字.否则,它是一个指向字符串的指针.因此-将它们作为IntPtr进行测试,然后存储一个字符串(Marshal.PtrToStringAuto)或一个数字.然后,当再次使用它们时,将需要重载函数以采用IntPtr或String.

而且..不,我没有要共享的代码.

另一种选择是在命令行模式下使用资源黑客,我想可以从VB.Net中完成.


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?

解决方案

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.


这篇关于在DLL文件中加载位图和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆