如何从此DLL修改DLL中的资源? [英] How to modyfy resource in a DLL from this DLL?

查看:395
本文介绍了如何从此DLL修改DLL中的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VC ++和ATL为IE编写插件. 这是一个简单的DLL,我有一个用作资源的文本文件. 答案有助于我做到这一点. >

我有一个有关更新资源的问题. MSDN 描述了如何这样做,但是有一个功能( BeginUpdateResource )需要带有资源的exe或dll文件名.

是否可以从 DLL 更新我的DLL中的资源?我可以轻松地以这种方式阅读它,但是要进行更新,我必须提供DLL的名称.有必要吗?

此外,如果我不提供DLL的完整路径,它将在桌面上查找文件,而不是在DLL的存储位置.我不知道为什么会这样.

解决方案

我从来没有尝试过这样做,所以我可能是错的,但是如果DLL可以更新自己的资源,我会感到惊讶.如果加载了DLL文件,则我希望包含DLL的文件被锁定以进行读取和对该文件的写入尝试失败.

不过,如果您想尝试,只需让DLL将其自己的路径传递给函数即可.

您可以使用 GetModuleFileName获取DLL的路径作为第一个参数传递DLL的HINSTANCE/HMODULE(如今它们是相同的).在DllMain中将HINSTNACE/HMODULE传递给您.

I'm writing an add-on for IE using VC++ and ATL. It's a simple DLL and I have a text file that I use as a resource. This answer helped me in doing this.

I have a question about updating resource. MSDN describes how to do it but there is a function (BeginUpdateResource) that need filename of exe or dll with resource.

Is it possible to update resource in my DLL from my DLL? I can easily read it that way, but to update I have to provide DLL's name. Is it necessary?

Also if I won't give full path to my DLL it looks for file on desktop and not where DLL is stored. I don't know why this behave like this.

解决方案

I have never tried to do this so I might be wrong, but I would be surprised if a DLL could update its own resources. If the DLL file is loaded then I would expect the file containing the DLL to be locked for reading and for write attempts to that file to fail.

Still, if you want to try, just have the DLL pass its own path to the function.

You can get your DLL's path using GetModuleFileName by passing your DLL's HINSTANCE / HMODULE (they are the same thing these days) as the first argument. The HINSTNACE / HMODULE is passed to you in DllMain.

这篇关于如何从此DLL修改DLL中的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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