开发者

c++ dynamic dll loading and functions defined in the loader

开发者 https://www.devze.com 2023-02-27 15:14 出处:网络
I have Program A (which is opensource, but I can not modify its sour开发者_开发问答ce), and DLL B, which is loaded by Program A dynamicly.

I have Program A (which is opensource, but I can not modify its sour开发者_开发问答ce), and DLL B, which is loaded by Program A dynamicly.

Is there a way, to use the functions defined in Program A by DLL B?

(Might help; Program A has a lot of .h header files, and all the functions I need are defined extern in these ...)


The extern defines that the linker that generates the A.exe can use the symbol. When you want to get the address of the symbol (function, variable,...) the symbol must be exported. This is usually not done for a program.

If your program A.exe does not provide you a pointer or means to get a pointer to a function, you are not able to use functions of the program A.exe in your DLL B.

Dirty hacks are possible though...


If you have a lot of such functions, it may be worth exporting them to the other library. I, for example, am working on application of 100 000 lines of code wth only 200 in executable file.


If your A program declares functions with __declspec(dllexport) or if you are able to compile your A program with your *.def file that lists DLL exports that you need in your DLL B then you may get that exported functions' addresses by GetProcAddress Win32 API function (passing module handle of executable that you may get by name or otherwise - see GetModuleHandle, GetModuleHandleEx)

0

精彩评论

暂无评论...
验证码 换一张
取 消