最近專案緊急,有一段時間沒寫部落格了。在專案開發過程中,同事問了乙個問題,我嘗試給他解決後,在此記錄一下。
在專案中,我針對二種不同的裝置,給上層封裝了一套c介面,即使用同乙個標頭檔案,呼叫不同的驅動庫,即可對裝置進行操作。同事在編寫上層應用時,不知道如何呼叫。本文講述的乙個方法是使用【loadlibrary】、【getprocaddress】、【freelibrary】來解決這個問題,接下來請看部分**實現。
#ifndef test_store_h
#define test_store_h
#ifdef _win32
#ifndef test_api
#define test_api __declspec(dllexport)
#endif
#else
#define test_api
#endif
typedef void ** qhandles;
#ifdef __cplusplus
extern "c"
#endif /* #ifdef __cplusplus */
#endif /* #ifndef test_h */
#include #include #include #include #include #include "windows.h"
#include "qcard_store.h"
typedef int (*test_enumstorehandle_p)(thandles *phstorehandles);
void test_qtf_enum()
else
/* 呼叫對應裝置的驅動庫 */
hdll = loadlibrary(_t("qcard_store.dll"));
if(hdll == 0)
/* 獲取庫檔案的函式位址 */
pfun = (test_enumstorehandle_p)getprocaddress(hdll, "test_enumstorehandle");
/* 列舉裝置 */
ret = pfun(&phstorehandles);
freelibrary(hdll);
if (ret <= 0)
else
}
android呼叫第三方庫
把第三方so放在新建的libs armeabi 中 因為android.mk檔案中的當前目錄跳到local path call my dir 即jni下,所以這個libs armeabi必須在jni下 android.mk local path call my dir warning local p...
Qt 呼叫第三方庫
一 製作動態庫c 動態庫 c 生成dll,專案名稱mydll 件 ifndef mdll h define mdll h ifdef mylibdll define mylibdll extern c declspec dllimport else define mylibdll extern c ...
Qt呼叫第三方C動態庫 so
此處的編譯器必須為交叉編譯器 以csdn檔案為例 1 將現有的檔案編譯為動態庫 gcc o fpic shared o libcsdn.so csdn.h csdn.c 2 將檔案新增到專案路徑 將libcsdn.so檔案和csdn.件複製到.pro檔案同級目錄 3 在.pro檔案中新增 libs ...