可以供MFC调用的,QT实现的DLL(使用qt-solutions的qtwinmigrate实现)

MFC和QT的消息循环机制不同,所以,要让QT写的DLL可以供MFC调用,要做一点特殊的处理

  1. #include <qmfcapp.h>  
  2. #include <qwinwidget.h>  
  3. #include <QtGui>  
  4.   
  5. #include <QtGui/QMessageBox>  
  6. #include <windows.h>  
  7. #include <QTextCodec>  
  1. #include "widget.h"  
  2.   
  3. BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )  
  4. {  
  5.     static bool ownApplication = FALSE;  
  6.     //加入本地语言支持  
  7.     QTextCodec::setCodecForTr(QTextCodec::codecForLocale());  
  8.     QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());  
  9.   
  10.     if ( dwReason == DLL_PROCESS_ATTACH )  
  11.     {  
  12.   
  13.         ownApplication = QMfcApp::pluginInstance( hInstance );  
  14.     }  
  15.     if ( dwReason == DLL_PROCESS_DETACH && ownApplication )  
  16.     {  
  17.         qApp->quit();  
  18.         delete qApp;  
  19.     }  
  20.   
  21.     return TRUE;  
  22. }  
  23.   
  24.   
  25. extern "C" __declspec(dllexport) int ShowDialog( HWND parent)  
  26. {  
  27.     QWinWidget win(parent, NULL, Qt::Window);  
  28.     win.showCentered();  
  29.     win.center();  
  30.   
  31.     QHBoxLayout hbox(&win);  
  32.     Widget *widget = new Widget(&win);  
  33.     widget->setWindowFlags(Qt::Window);  
  34.     hbox.addWidget(widget);  
  35.   
  36.     win.show();  
  37.     qApp->exec();  
  38. }  

http://blog.csdn.net/small_qch/article/details/6743803

https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate

原文地址:https://www.cnblogs.com/findumars/p/4851314.html