问题描述:
软件同时集成两种IPC的SDK时,遇到dll同名的情况,因此在调用时会出现冲突的情况。
解决方法如下:
采用动态加载dll库的方法。
#include "common.h"
#include "iostream"
#include "tchar.h"
#include "windows.h"
using namespace std;
using namespace cv;
#ifdef _DEBUG
#pragma comment(lib,"opencv_world320d.lib")
#else
#pragma comment(lib,"opencv_world320.lib")
#endif
// 声明所需使用的函数
typedef CTLEduCameraDH * (*PCTOR)();
typedef void (*INITDHSDK)(void*);
typedef void(*RELESDHSDK)();
typedef BOOL (WINAPI *INITOBJ)(TLEduDHCameraParam*); // WINAPI翻译为汇编即为长调用
typedef BOOL(*START)();
int main()
{
/************ IPC sdk 动态库设置:START *****************/
TCHAR chCurDir[MAX_PATH] = { 0 };
GetCurrentDirectory(MAX_PATH, chCurDir); // 获取当前程序所在的目录
SetCurrentDirectory(_T("..\\Debug\\dh")); // 设置此目录为搜索起始目录
HMODULE hMod_dh = LoadLibrary(_T("THdhIPCSDK.dll")); // 动态加载dll库
if (NULL == hMod_dh)
{
cout << "E: LoadLibray ipc SDK.DLL Failed!" << endl;
FreeLibrary(hMod_dh);
getchar();
return 1;
}
else
{
cout << "I: LoadLibray DH ipc SDK.DLL Success!" << endl;
}
SetCurrentDirectory(chCurDir); // 还原搜索目录
/************ IPC sdk 动态库设置:END *****************/
TLEduDHCameraParam *param_T = (TLEduDHCameraParam *)malloc(sizeof(TLEduDHCameraParam));
CCameraReciver *recv_T = new CCameraReciver;
param_T->m_work_mod = 1;
param_T->m_in_video_height = 1080 * 2;
param_T->m_in_video_width = 1920 * 2;
param_T->g_lRealPort = 0;
param_T->m_in_audio_channels = 2;
param_T->m_in_audio_fmt = 0;
param_T->m_in_audio_sample_rate = 16000;
param_T->m_in_audio_type = 0;
param_T->m_in_decode_type = 1; // 1为软解;2为硬解
recv_T->m_type = 1;
param_T->m_pReciver = recv_T;
strcpy(param_T->s_ipc_IP, "192.168.2.243"); // IP地址
strcpy(param_T->s_ipc_UserName, "admin"); // 用户名
strcpy(param_T->s_ipc_Password, "th12345678"); // 密码
/********* IPC: START **********/
CTLEduCameraDH * pDHObj;
PCTOR pCtor = (PCTOR)GetProcAddress(hMod_dh, "CreateObj"); // 获取函数的地址指针
if (pCtor == NULL)
{
cout << "E: Function CTest() not found.\n";
}
pDHObj = pCtor(); // 调用CreateObj函数
INITDHSDK pInitDH = (INITDHSDK)GetProcAddress(hMod_dh, "InitDHSDK"); // 获取函数的地址指针
if (pInitDH == NULL)
{
cout << "E: pInitDH not found.\n";
}
else
{
pInitDH(NULL); // 调用InitDHSDK函数
}
INITOBJ pInitObj = (INITOBJ)GetProcAddress(hMod_dh, "InitObj"); // 获取函数的地址指针
if (pInitObj == NULL)
{
cout << "E: pInitObj not found." << endl;
}
else
{
//__asm { MOV ECX, pDHObj}; // 相当于取this指针送到ECX寄存器中
int flag = pInitObj(param_T); // 调用InitObj函数
if(flag)
cout << "I: InitObj Success." << endl;
}
START pSTART = (START)GetProcAddress(hMod_dh, "Start");
if (pSTART == NULL)
{
cout << "E: pSTART not found.\n";
}
else
{
//__asm { MOV ECX, pDHObj}; // 相当于取this指针送到ECX寄存器中
int flag_T = (pSTART)();
if (TRUE == flag_T)
cout << "I: Techer IPC Start Success " << endl;
else
cout << "E: Techer IPC Start Fail " << endl;
}
/********* IPC: END **********/
getchar();
RELESDHSDK pRelesObj = (RELESDHSDK)GetProcAddress(hMod_dh, "ReleaseDHSDK");
pRelesObj(); // 释放资源
if(hMod_dh)
FreeLibrary(hMod_dh); //释放库句柄
if(hMod_mr)
FreeLibrary(hMod_mr); //释放库句柄
return 0;
}