如何在程序中实现插件的功能?

henryzc 2003-10-17 01:49:50
主程序提供框架,在视中显示插件的界面。其中的插件由动态库实现。
主程序与插件之间通过公用的方法进行通讯,如告诉插件程序显示界面、退出。

哪位高手帮忙,分数好说
...全文
224 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
robothn 2004-01-15
  • 打赏
  • 举报
回复
/*
D2Loader SDK
Copyright (C) 2000, 2001 Onlyer(onlyer@263.net)

This SDK is based on original Diablo2 game library,
Diablo2 is a trademark of Blizzard Entertainment.
This library is done by volunteers and is neither
supported by nor otherwise affiliated with Blizzard Entertainment.
You should NEVER use the library on communicate use.

It is distributed WITHOUT ANY WARRANTY, use it
at your own risk.
*/
/*
How does D2loader Plugin works:
* 1. The Loader will search *.dll files under plugin\ directory and
try to load it.
* 2. If the dll is loaded sucessfully, then the loader will try
to find if the dll have an exported entry named "QueryInterface"
(See QueryInterfaceFunc)
* 3. After got the function "QueryInterface" entry address, That function
will be called, and the plugin dll should return a pointer to
a PLUGIN_INTERFACE struct, this struct contains:
1).a DWORD magicword. (should equal to PLUGIN_MAGICWORD, used for verify)
2).a DWORD version number. (should equal to PLUGIN_VERSION)
3).a LPCSTR description. (description of your plugin, which will be
logged into file "d2loader.log" if the loader is started
with option -l or -log)
4).a pointer to function fpEntry, as described below
* 4. Then the loader will continue to load the game and the entry function
fpEntry will be called at certain condition.
1).Just after step 3, the plugin dll is loaded, the loader
will call fpEntry with dwReason = REASON_INIT and
lpData = a pointer to PLUGIN_DATA_INIT struct
2).For all other reasons, the lpData parameter will be
a pointer to D2PARAM struct (see d2param.h), you may
get useful client information from this struct. do NOT
modify data in this struct if you are not sure.
(see chatlog plugin source code for a sample use of
D2PARAM struct)
3).If the loader is going to unload a plugin, fpEntry will
be called with REASON_CLEANUP.
4).You can easily find out what does each reason mean from
their name. just notes here: dwReason maybe a a combination
of more than one reason only except REASON_INIT and
REASON_CLEANUP will not. also, two notices here:
a. ENTER and CLEANUP of the same set will never be combined
(e.g: if REASON_ENTER_GAME is in dwReason, then
REASON_LEAVE_GAME will surely not)
b. there will never be more than one ENTER or LEAVE reasons
(e.g: if REASON_ENTER_GAME is in dwReason, then
other ENTER reason like REASON_ENTER_CHANNEL and
REASON_ENTER_MAIN_MENU will surely not)
5).Here is an sample log of how dwReason is called.
(You may use option -l to check it)
a. Start the game, REASON_INIT will be sent
b. Enter main menu, REASON_ENTER_MAIN_MENU is sent
c. Connect to battle.net and logged in,
REASON_LEAVE_MAIN_MENU |REASON_ENTER_CHANNEL is sent
after the player select a character
d. create a join a game in battle.net
REASON_LEAVE_CHANNEL |REASON_ENTER_GAME is sent
e. quit game,REASON_LEAVE_GAME |REASON_ENTER_CHANNEL is sent
f. quit channel, REASON_LEAVE_CHANNEL |REASON_ENTER_MAIN_MENU
g. exit, REASON_CLEANUP is sent.
6).The function fpEntry should return TRUE if it executed successfully.
return a FALSE value will cause the loader to unload it.
*/
暗黑 d2loader sdk 里的,我现在就参照这种机制写个插件系统
henryzc 2004-01-14
  • 打赏
  • 举报
回复
能不能提供个例子?谢谢,不要纸上谈兵
unalone 2004-01-11
  • 打赏
  • 举报
回复
传递MFC类的指针当然不可以了,应该传递视的hWnd,接下来就一切OK了。
Ziox 2003-12-03
  • 打赏
  • 举报
回复
gz
henryzc 2003-11-28
  • 打赏
  • 举报
回复
orbit(桔皮干了),你说的是什么软件?我想看看。不过还是等待高手ing
吹泡泡的小猫 2003-11-27
  • 打赏
  • 举报
回复
呵呵,winmsg消息精灵 就是个例子,主框架非常简单,没有任何功能,功能全部由插件完成
yaoyuhang 2003-11-25
  • 打赏
  • 举报
回复
听课ing
henryzc 2003-11-20
  • 打赏
  • 举报
回复
hq1978(happy),就像你说的一样,主程序可以调用动态库,并通过统一的函数名和参数把动态库中的对话框显示出来,但是如何让动态库中的对话框嵌入在主程序的视中?
hq1978 2003-11-14
  • 打赏
  • 举报
回复
很多插件是这样做的
定义插件动态dll的接口规范,就是说dll中必须要实现的函数,这些函数有给系统相应信息的,有功能执行的,这些函数有统一的函数名和参数。
指定这些dll放在同一个目录下。
在系统启动时遍历该目录下的所有dll,并将其用LoadLibrary装载,然后调用dll的那些统一的接口就可以了。
只要符合你规范的dll都可以作为插件
henryzc 2003-11-03
  • 打赏
  • 举报
回复
看来这个问题还真就解决不了了
null1 2003-10-30
  • 打赏
  • 举报
回复
关注
qrlvls 2003-10-30
  • 打赏
  • 举报
回复
DLL 当然不应该仅仅包含资源,如果你要使你的软件有充分的扩展余地而不用推出新版本的话,可以考虑把有可能用到的资源的信息打包传递给DLL,由插件来处理这些资源,当然,在设计时会相当麻烦,不过也没有别的办法了,至少我没有,一举两得是很麻烦的
microran2000 2003-10-28
  • 打赏
  • 举报
回复
我没有尝试过使用DLL实现一个前台界面的消息响应代码,你可以尝试把框架客户区的父窗口指针传递到输出函数参数中。至于算法及处理逻辑,我想这没有什么

henryzc 2003-10-27
  • 打赏
  • 举报
回复
microran2000,插件除了提供界面外,还应该包括算法、数据处理规则,如果dll仅仅提供资源的话,主程序将会非常复杂,插件也起不到该起的作用。

郁闷ing
qrlvls 2003-10-27
  • 打赏
  • 举报
回复
可以在动态库中实现同名的接口函数
可以做成 COM 组件,在自注册函数中添加在应用程序组的注册表项中增加自己路径的方法
应用程序可以通过注册表查询有哪些插件
并通过 GetProcAddress 判断插件是否实现了该接口函数
如果实现了,则把参数传递给动态库中该函数即可
microran2000 2003-10-25
  • 打赏
  • 举报
回复
听了你的解释,我觉得你说的插件实际上相当于一个资源,实际上你只要把该对话框资源作为模板创建一个视图即可。但是你还需要为视准备窗口过程,即响应窗口消息。这部分代码如果写到DLL中,势必比写在exe文件中复杂的多。我觉得你可以规定对话框中控件标识要求一致。DLL仅提供资源,这样可能会简单的多。
会思考的草 2003-10-25
  • 打赏
  • 举报
回复
插件其实就是一个dll啦,放在特定目录下,你的主程序启动的时候会搜索该目录,然后把独立的各个模块分别加载到进程的空间中去。这个dll和一般的dll有区别,初始化入口是你自己定义的,别的软件用不了。
henryzc 2003-10-25
  • 打赏
  • 举报
回复
插件不需要绘制图形,在插件中的对话框可以嵌入到主程序的视中。我试着把主程序的视类指针传递到动态库的接口中,结果总是失败。

哪位大虾赶紧出招啊,谢谢
guoyin 2003-10-24
  • 打赏
  • 举报
回复
gz
microran2000 2003-10-23
  • 打赏
  • 举报
回复
即要求客户区的界面绘制要求由插件来完成。这应该不是件困难的事,因为客户端重绘需要处理OnDraw重载函数,即WM_DRAW?消息。只要你把客户区对象的设备描述表指针pDC和客户区大小传送给插件就可以了。通过插件接口方法调用或者输出函数调用,即可以完成界面的绘制。
其实你应该关心如何实现插件的框架,而不应该关心插件要干什么。因为插件最终是要和主进程加载到同一地址空间的。
加载更多回复(8)

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧