How to modyfy resource in a DLL from this DLL?

2019-07-29 13:00发布

问题:

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.

回答1:

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.