DLL Get Symbols From Its Parent (Loader)

2019-02-25 16:57发布

问题:

I am porting a program to MS Windows. This program uses dynamically loaded plugins. The plugins reference symbols in the main program. I cannot even get the DLLs past the linker without all symbols being resolved. Is there a way to solve this?

回答1:

(Sorry, I'd like to ask for clarification in a comment but I'm too much of a newbie to be allowed.)

When you say the plugins "reference symbols in the main program", is it about referencing functions or data? Also, what language/compiler are you using?

Assuming it's only about functions, and in C/C++: it's possible to export a function from a .EXE as if it were a DLL. Just specify __declspec(dllexport) in front of the function definition in the .EXE . When compiling the .EXE, a .LIB file should get generated, which you can then use as input when linking each plugin.