Search code examples
c++windowsdllembedded-resourceloadlibrary

Can a DLL load a resource from calling EXE?


Background

I have two C++ projects. One EXE and one DLL. The EXE loads the DLL and call its single exported function. Eventually, I will generate even more DLLs that will be loaded and run by the EXE

Motivation

EXE and all DLLs will use some resource. So, instead of adding the resource to all DLLs, I'd like to add it, once, to the EXE and wish the DLL to load the resource from the caller EXE.

Attempt

I already know how to load my own resource using: FindResource(), LoadResource(), LockResource(). All I'm missing is the hModule to the caller process.

In addition I've read Can you get the caller DLL or executable module from the callee

Question (TL;DR)

So, if my approch describbed above is the right one, then, How do I get an HMODULE to the caller module withing a DLL?


Solution

  • Bad understanding on how resource loading works led me to ask this.

    I think that the following illustration will shed some light for those who are/were confused as me.

    enter image description here