• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Codejie's C++ Space

            Using C++

            LingosHook:Plugins


                LingosHook最近的版本發布有五個多月了,下載量也超過2500了~看來Lingoes真的很流行,單詞本真的很需要啊。。。

                從目前得到的反饋情況看,有一半多的都是增強功能。如果把這些功能一一加到LingosHook中,總感覺會使其變得臃腫,甚至可能就偏離了作為單詞本的主線了。但有些功能確實可以很有用的,比如單詞的導出,等等。
                既要添加功能,又不能影響原有的框架,想來想去,總沒有個好的方案。幾天前LP收拾書柜時忽然問我--“Delphi你還會嗎?”接過兩本厚厚的《Delphi5 開發指南》,突然就想起十年前曾用Delphi開發的CBE(Cell Broadcast Equipment,不知道是否有人記得這個。。)程序來,那其中用到的‘Plugins’方法應該可以解決這個問題。
                這個‘Plugins’--看著和說著都很好聽,當然了,當時確實也很得意。實際說起來原理很簡單,就是動態加載DLL,利用DLL封裝所需功能。不過現在想想,那時自己還真的很有想象力啊,因為當時只是聽說過‘Plugins’技術,從來不知道該怎么做,總覺得應該是個非常非常高深的技術,都沒敢去研究過。自己把這種DLL叫做‘Plugins’,也只是‘趕潮流’,傍個好聽的名字便于去吹牛而已,沒想后來發現這還真是一種Plugins的實現方式,非常地驚訝。。。
                當然了,自己的這個‘Plugins’實際就是簡單的DLL調用,原理很簡單--定義幾個標準接口,作為‘Plugins’的DLL實現這些接口,然后應用掃描指定的DLL文件,并檢查這些接口是否存在,如果存在,就加載到應用中,使用是,調用定義好的接口來完成所需功能。

                下面是定義的接口類:

            #ifndef __ACTIVITYOBJECT_H__
            #define __ACTIVITYOBJECT_H__

            #include 
            "wx/wx.h"

            class CDBAccess;

            class ActivityObject
            {
            public:
                
            struct PropertyData
                
            {
                    wxString m_strLabel;
                    wxString m_strName;
                    wxString m_strVersion;
                    wxString m_strAuthor;
                    wxString m_strDescription;
                    wxString m_strDetail;
                }
            ;
            public:
                ActivityObject();
                
            virtual ~ActivityObject();

                
            virtual int Init(int fparam = 0int sparam = 0return 0; }
                
            virtual void Final() {}

                
            virtual int LoadProperty(PropertyData& data) const = 0;

                
            virtual int Run() = 0;

                
            virtual bool NeedDBAccess() const return false; }
                
            virtual bool NeedTagAccess() const return false; }

                
            void SetDBObject(CDBAccess* obj);
            protected:
                CDBAccess
            * _objDBAccess;
            }
            ;

            #endif

                然后是調用接口的代碼:
            int CPluginObject::LoadPlugin(int index, const wxString &plugfile)
            {
                wxDynamicLibrary lib(plugfile);
                
            if(!lib.IsLoaded())
                    
            return -1;

                 GetActivityPtr ptr 
            = (GetActivityPtr)lib.GetSymbol(wxT("GetActivity"));
                 ActivityObject
            * act = ptr();
                 ActivityObject::PropertyData data;
                 
            if(act->LoadProperty(data) == 0)
                 
            {
                     _mapActivity.insert(std::make_pair(index, plugfile));

                     g_objTrigger.OnPluginLoad(index, data);
                 }

                 lib.Unload();

                 
            return 0;
            }

               具體功能實現代碼在這里:
            class WordExport : public ActivityObject
            {
            public:
                WordExport();
                
            virtual ~WordExport();

                
            virtual int Init(int fparam = 0int sparam = 0return 0; }
                
            virtual void Final() {}

                
            virtual int LoadProperty(PropertyData& data) const;

                
            virtual int Run();

                
            virtual bool NeedDBAccess() const return true; }

            }
            ;

            extern WordExport* _theActivity;

            #include <windows.h>

            #include 
            "Exports.h"
            #include 
            "WordExport.h"

            LINGOSHOOK_PLUGINS_API ActivityObject
            * GetActivity()
            {
                _theActivity 
            = new WordExport();
                
            return _theActivity;
            }


            int DLLInit()
            {
                
            return 0;
            }


            void DLLFinal()
            {
                
            if(_theActivity != NULL)
                    delete _theActivity, _theActivity 
            = NULL;
            }


            ///////////
            BOOL APIENTRY DllMain(HANDLE hModule, DWORD uCallReason, LPVOID pReserved)
            {
                
            switch(uCallReason)
                
            {
                
            case DLL_PROCESS_ATTACH:
                    
            if(DLLInit() != 0)
                        
            return FALSE;
                    
            break;
                
            case DLL_THREAD_ATTACH:
                    
            break;
                
            case DLL_THREAD_DETACH:
                    
            break;
                
            case DLL_PROCESS_DETACH:
                    DLLFinal();
                    
            break;
                
            default:
                    
            return FALSE;
                }
            ;

                
            return TRUE;
            }


            ////

            WordExport
            * _theActivity = NULL;


            WordExport::WordExport()
            : ActivityObject()
            {
            }


            WordExport::
            ~WordExport()
            {
            }


            int WordExport::LoadProperty(PropertyData& data) const
            {
                data.m_strLabel 
            = wxT("WordExport");
                data.m_strName 
            = wxT("Word Export");
                data.m_strVersion 
            = wxT("0.0.1");
                data.m_strAuthor 
            = wxT("codejie");
                data.m_strDescription 
            = wxT("Export words from LingosHook to a Text file.");
                data.m_strDetail 
            = wxT("NONE.");

                
            return 0;
            }


            int WordExport::Run()
            {
                
            return -1;
            }


                運行時的樣子如下:


                怎么樣,挺像回事吧。。。

            posted on 2010-12-29 01:10 codejie 閱讀(1968) 評論(1)  編輯 收藏 引用 所屬分類: C++輪子精神LingosHook

            評論

            # re: LingosHook:Plugins[未登錄] 2010-12-29 11:22 潘孫友

            灰常像樣了,呵呵  回復  更多評論   

            公告

            Using C++

            導航

            統計

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品蜜桃久久久久久| 无码任你躁久久久久久久| 久久无码人妻一区二区三区午夜| 久久亚洲中文字幕精品有坂深雪| 国内精品久久久人妻中文字幕| 国产成人精品久久综合| 一本色道久久综合| 99久久国产热无码精品免费| 国产毛片久久久久久国产毛片| 国产精品亚洲综合久久| 欧美亚洲另类久久综合| 伊人色综合九久久天天蜜桃| 久久99免费视频| 亚洲精品乱码久久久久久按摩 | 精品欧美一区二区三区久久久| 久久亚洲精品无码播放| 999久久久免费精品国产| 99久久这里只精品国产免费| 99久久www免费人成精品| 蜜臀av性久久久久蜜臀aⅴ麻豆| 91精品久久久久久无码| 色婷婷综合久久久久中文一区二区 | 国内精品久久久久久久coent | 亚洲日韩欧美一区久久久久我 | 久久人人爽人人爽人人片av麻烦| 国产日产久久高清欧美一区| 久久亚洲中文字幕精品一区| 久久久青草青青国产亚洲免观| 国内精品久久久久| 国产精品久久久久jk制服| 人妻少妇久久中文字幕 | 欧美伊人久久大香线蕉综合69| 久久久久夜夜夜精品国产| 日韩人妻无码精品久久久不卡 | 欧美综合天天夜夜久久| 久久夜色精品国产噜噜麻豆| 中文字幕热久久久久久久| 久久精品免费全国观看国产| 亚洲伊人久久成综合人影院 | 国产精品久久久久乳精品爆 | 性欧美丰满熟妇XXXX性久久久|