NukerDoggie
NukerDoggie

Reputation: 3

How to link a DLL for LoadLibrary() use (in C++ on Windows ) and do import of variables from the calling exe

On Windows I have a program executable which is the target of DLL injection via a Windows hook. The hook injects my DLL into the program space of the target by forcing it to do a LoadLibrary(). I want to export a particular variable from the exe to the DLL so that the DLL can read the contents of that variable.

Since this is dynamic linking, the exe and DLL are not linked together by the linker. I can't build the DLL because I get linker error 2001 - unresolved external - on the variable I'm trying to import from the exe. I tried using this in the DLL: extern "C" __declspec(dllimport) EGL_UINT8 *ssFrameDataBlock[];

But this does not resolve the link error. Obviously I'm missing some steps. How do I export a symbol from the exe and import it into the DLL for dynamic linking? What is the correct syntax on each side for the export and import?

Upvotes: 0

Views: 310

Answers (1)

SoronelHaetir
SoronelHaetir

Reputation: 15164

Did you remember to decorate the executable's definition of the variable with __declspec(dllexport)? You will then need to provide the exe's .lib file as part of the DLL build.

If you do not export at least one symbol (whether by dllexport, or a EXPORTS statement in a def file or on the command line) no .lib file will be produced.

If you can't provide a .lib to the DLL build you could also use GetProcAddress() from within the DLL code (despite the name it can obtain the address of any export, not just functions).

Upvotes: 1

Related Questions