Codejie's C++ Space

Using C++

LingosHook:Plugins under wxWidget


    这几天一直在被Plugins折腾,用老办法用wxWidget实现插件方式一直都失败,主要是在DLL中创建的窗口无法获得Application Instance,导致窗口弹出时,直接CORE,很是苦恼。。。后来尝试将主窗口的Instance和Window作为参数传给DLL中的窗口,弹出没有问题,但当窗口关闭是,也会引起主窗口关闭,怀疑是公用消息队列所致,又是苦恼了几天~
    好在现在世界无限大,找来找去,还真发现早有前辈实现了这些,啥也不管了,COPY & PASTE 先,爸爸说的好--“天下文人是一家”,我觉得程序员亦是如此。。。
    原帖在这,敬请移步--http://wxforum.shadonet.com/viewtopic.php?t=13178&highlight=plugin

    虽还没有太弄懂其原理,但大体看原帖应该也碰到了和我一样的问题。所以其在DLL创建窗口前,先初始了一个App来接管或者封装住后面的窗口。实在是高人,至少我没有想到这样,用到的那些函数也从没见过,实在是高啊。。。这里我还有些糊涂,此时DLL中的窗口运行在哪个进程中?我还不想在LingosHook中引入锁。。。

    下面是主要的,也是重要的代码。
#ifndef __EXPORTS_H__
#define __EXPORTS_H__

//http://wxforum.shadonet.com/viewtopic.php?t=13178&highlight=plugin

#include 
"wx/wx.h"
#include 
"wx/msw/private.h"

#define IMPLEMENT_PLUGIN(name)                                                              \
    
extern "C" __declspec(dllexport) ActivityObject* GetActivity() return new name; }     \
                                                                                            \
    
class name##DLLApp : public wxApp                                                       \
    
{                                                                                       \
    }
;                                                                                      \
    IMPLEMENT_APP_NO_MAIN(name##DLLApp)                                                     \
                                                                                            \
    BOOL APIENTRY DllMain(HANDLE hModule, DWORD uCallReason, LPVOID pReserved)              \
    
{                                                                                       \
        
switch(uCallReason)                                                                 \
        
{                                                                                   \
        
case DLL_PROCESS_ATTACH:                                                            \
            
{                                                                               \
                wxSetInstance((HINSTANCE)hModule);                                          \
                
int argc = 0char* argv = NULL;                                            \
                wxEntryStart(argc, 
&argv);                                                  \
                
return TRUE;                                                                \
            }
                                                                               \
            
break;                                                                          \
        
case DLL_THREAD_ATTACH:                                                             \
            
break;                                                                          \
        
case DLL_THREAD_DETACH:                                                             \
            
break;                                                                          \
        
case DLL_PROCESS_DETACH:                                                            \
            wxEntryCleanup();                                                                \
            
break;                                                                          \
        
default:                                                                            \
            
return FALSE;                                                                   \
        }
;                                                                                  \
                                                                                            \
        
return TRUE;                                                                        \
    }
                                                                                       \
    

#endif

    上面代码被我去掉了几行,没别的意思,只是感觉么什么用处,当然也可能自己道行还不够,没体会到其中奥秘。不过去掉了还是能正常使用,如下图。有兴趣的,请去看原帖。




<---- 蛋疼的分割线---->

    知道啥叫‘蛋疼’不。。。为了搞定这个Plugins,特意写了Test工程。。。搞死我了。。。

posted on 2011-01-07 18:39 codejie 阅读(1670) 评论(0)  编辑 收藏 引用 所属分类: C++LingosHook


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

Using C++

导航

统计

留言簿(73)

随笔分类(513)

积分与排名

最新评论

阅读排行榜

评论排行榜