/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/
#include <windows.h>
#include "IPlugin.h"
#include <string>
typedef IPlugin* (*PLUGIN_FACTORY)(); // function pointer
bool LoadPlugins();
bool LoadPlugin(const char * pluginFullname, HMODULE * mod, IPlugin*& pluginRef);
bool UnLoadPlugins();
bool UnLoadPlugin(HMODULE hMod, IPlugin* pluginRef);
typedef void (*PLUGIN_CLEANUP)(IPlugin*);
HMODULE hMods[2];
IPlugin* plugins[2];
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
int i=0;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_LBUTTONDOWN:
LoadPlugins();
return 0;
case WM_RBUTTONDOWN:
UnLoadPlugins();
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
bool LoadPlugins()
{
LoadPlugin("TextPlugin.dll", &hMods[0], plugins[0]);
LoadPlugin("GraphPlugin.dll", &hMods[1], plugins[1]);
return true;
}
bool LoadPlugin(const char * pluginFullname, HMODULE * mod,IPlugin*& pluginRef)
{
HMODULE hMod = ::LoadLibrary(pluginFullname);
(*mod) = hMod;
if(hMod == NULL)
{
return false;
}
PLUGIN_FACTORY func = (PLUGIN_FACTORY)::GetProcAddress(hMod, "CreatePlugin");
if(func == NULL)
{
return false;
}
pluginRef = (*func)();
std::string name = pluginRef ->GetName();
::MessageBox(NULL, name.c_str(), "", MB_OK);
return true;
}
bool UnLoadPlugins()
{
UnLoadPlugin(hMods[0], plugins[0]);
UnLoadPlugin(hMods[1], plugins[1]);
return true;
}
bool UnLoadPlugin(HMODULE hMod, IPlugin* pluginRef)
{
PLUGIN_CLEANUP func = (PLUGIN_CLEANUP)::GetProcAddress(hMod, "ReleasePlugin");
(*func)(pluginRef);
if(! ::FreeLibrary(hMod) )
{
return false;
}
return true;
}
没有合适的资源?快使用搜索试试~ 我知道了~
插件体系入门源码(vs2005)
共16个文件
vcproj:4个
user:4个
h:3个
5星 · 超过95%的资源 需积分: 10 93 下载量 17 浏览量
2010-02-10
11:16:10
上传
评论
收藏 16KB RAR 举报
温馨提示
纵“狗”搜索出大量有关插件系统的文章,但大都光说不练。搞得我等“小鸟”头晕目眩。后来,在国外网站上找到了一篇实战派文章。 果然是大道至简,插件体系原来如此简单。希望他人少走弯路。
资源推荐
资源详情
资源评论
收起资源包目录
plugin.rar (16个子文件)
plugin
PluginArchitecture.suo 36KB
WinPlatform
main.cpp 4KB
WinPlatform.vcproj 4KB
WinPlatform.vcproj.PC-200909082350.Administrator.user 1KB
IPlugin.h 148B
PluginArchitecture.sln 2KB
GraphPlugin
GraphPlugin.vcproj 4KB
GraphPlugin.h 413B
GrapPlugin.cpp 92B
GraphPlugin.vcproj.PC-200909082350.Administrator.user 1KB
TextPlugin
TextPlugin.vcproj 4KB
TextPlugin.vcproj.PC-200909082350.Administrator.user 1KB
TextPlugin.cpp 89B
TextPlugin.h 411B
PluginArchitecture
PluginArchitecture.vcproj.PC-200909082350.Administrator.user 1KB
PluginArchitecture.vcproj 2KB
共 16 条
- 1
资源评论
- ssh_12345678902012-11-10够清楚 也有深度 谢谢分享
- m_stefanie2013-12-12好东西,参考了,不过缺少详细注释啊
- lh2582013-11-29好东西,比较简单,又能够深入解析插件原理
- 戒昔2012-07-27够清楚 也有深度 谢谢分享
- a1papaxiong1a2012-02-22好东西,参考了,不过缺少详细注释啊
dreamcs
- 粉丝: 121
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功