QLibrary 動態載入外部庫檔案

來源:互聯網
上載者:User
/*轉載請註明出處,謝謝*/

背景:想搭一個軟體系統,包含一個主模組,一堆子模組(用於擴充功能)。主模組是一個可執行程式,子模組為動態庫,可以載入在主模組中。

問題:每添加一個擴充功能就要修改一下主模組的來源程式,在其中添加標頭檔,lib檔案,然後重新編譯。很是麻煩。

目標:主模組讀一個設定檔,根據其中的內容,動態載入子模組的DLL,以實現擴充功能靈活配置,而不需要每次都修改和重新編譯主模組。

下面是個例子:

子模組代碼:

extern "C" __declspec(dllexport) int print2(int a, int b);

int print2(int a, int b){printf("VideoDecoderDLL printint!\n");return (a+b);}

主模組代碼:

#include <QLibrary>void Shell::Test(){//m_vd->print();int *out=0;typedef int (*myfun)(int, int);       // 定義匯出函數類型  QLibrary hdll( "I:/testDll/shell/VideoDecoderD.dll" );        //載入dll,目前的目錄  if(hdll.load())  {  myfun fun1 = (myfun)hdll.resolve("print2");        //用resolve來解析fun1函數  if ( fun1 )       //解析成功則進行運算並提示相關資訊  {  printf("解析成功\n");printf("%d\n",fun1(2,3));  }  else{printf("解析失敗\n");}}  }

目前還沒解決如何載入一個類,有知道辦法的朋友歡迎留言。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.