一个DLL需要访问其应用程序的符号 [英] a DLL need to access symbols of its application
问题描述
在C ++中,DLL可以访问加载它的应用程序的一些符号吗?
我有一个加载插件(dll)的应用程序,这些插件需要访问应用程序的一些API。
In C++, is it possible for a DLL to access some symbols of the application that loaded it ? I have an application that load plug-ins (dll), and these plug-ins need to access some API of the application.
是否可以实现这一点,而不需要创建一个共享此API的新DLL?
Is it possible to achieve this without creating a new DLL that share this API ?
是否在这种情况下适用的函数指针的结构?
Is a struct of function pointers suitable in this situation ?
示例:在宿主应用程序中定义的bool Log(char *)函数和需要记录某些事件的插件。
example: a bool Log(char*) function defined in the host application and a plug-in that need to log some events.
推荐答案
另一个将回调接口传递到插件DLL的投票。即回调接口...
Another vote for passing a callback interface into the plug-in DLL. I.e. the callback interface...
class IHostApplication
{
public:
virtual bool Log(const wchar_t* ip_log_string) = 0;
};
DLL插件界面
class IPlugin
{
public:
virtual void InitializePlugin(IHostApplication *ip_host) = 0;
};
主机将加载插件DLL(如果需要,可动态),然后将其自身作为IHostApplication *到插件,启用任何可能需要的回调。
The host would load the plug-in DLL (dynamically if necessary), and then pass itself as an IHostApplication* to the plugin, enabling any callback you might want.
这篇关于一个DLL需要访问其应用程序的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!