mfc调用qt的dll

1. 之前的准备工作

下载qtwinmigrate-2.8-opensource第三方库,
下载DEPENDS工具(用于检测生成的qt库,缺少哪些库,检测到之后放到mfc中的exe目录下)

2. qt部分

项目中引入qwinwidget.cpp qwinwidget.h qmfcapp.cpp qmfcapp.h四个文件(添加新文件,保证pro文件已经被修改)
.pro 添加 CONFIG += dll

main.cpp 如下:
#include "entrance.h"
#include <QApplication>
#include <qmfcapp.h>
#include <qwinwidget.h>


#include <QtGui/QMessageBox>
#include <windows.h>






BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
{
   static bool ownApplication = FALSE;


   if ( dwReason == DLL_PROCESS_ATTACH )
   ownApplication = QMfcApp::pluginInstance( hInstance );
   if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
   delete qApp;


   return TRUE;
}


extern "C" __declspec(dllexport)int main(int argc, char *argv[])
{
QApplication a(argc, argv);


Entrance* m_pEntrance = Entrance::getInstance();
m_pEntrance->SetText();
m_pEntrance->show();
return a.exec();
}

3. mfc部分

// TODO: 在此添加控件通知处理程序代码
HMODULE mod = LoadLibrary(TEXT("./QtTestToMFCDLL.dll"));
DWORD l_Error = GetLastError();


//这个是测试Qt生成的Dll的部分,先动态载入,再使用导出的函数  


if (mod)


{
//m_iNum++;
//typedef int(*Mymain)(int argc, char *argv[]);
//Mymain mmain = (Mymain)GetProcAddress(mod, "main");
//char* b = "abc";
//char**a = &b+m_iNum;
//mmain(0, a);


typedef void(*MySetText)();
MySetText mSetText = (MySetText)GetProcAddress(mod, "SetText");




FreeLibrary(mod);


}


else


{


CAboutDlg aboutDlg;


aboutDlg.DoModal();


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值