QT use DLL from VC6



  • I got DLL build by vc6 ,here is the function inside:
    #ifndef DLL_API
    #define DLL_API extern "C" __declspec(dllimport)
    #endif

    #define WIN_API __stdcall

    ....................
    DLL_API void WINAPI HTDrawTopPentagon(HDC hDC,int nCenterX,int nCenterY,COLORREF clr);
    ...................
    in QT I want to use these funtions.
    will it work if I program a QT project like this:
    "
    QLibrary myLib("dll_name");

    typedef int (MyPrototype)(QPixmap ,int,int,QColor);
    MyPrototype myFunction = (MyPrototype) myLib.resolve("HTDrawTopPentagon");
    myFunction test;
    will test work?
    or should i typedef int (*MyPrototype)(HDC ,int,int,COLORREF);in QT?



  • The function has no "int" return but "void".



  • Hi, calling functions in VC6 DLLs is possible, easiest I think is to declare them for example:

    auto HTDrawTopPentagon = (int (WINAPI *)(HDC,int,int,COLORREF)) QLibrary("dll_name").resolve("HTDrawTopPentagon");
    

    then to call it, first you need to have a DC, which I think you cannot get from a QPixmap, to test you can use your MainWindow's winId. Also I think you need to convert from QColor to COLORREF. So perhaps something like this:

    QColor qcolor("red");
    HTDrawTopPentagon(GetDC(HWND(this->winId())),100,100,RGB(qcolor.red(),qcolor.green(),qcolor.blue()));
    

    @msue: Yes I saw that now, but it shouldn't matter.

    Edit: if you're using MinGW compiler, you need to add CONFIG += c++11 to your .pro file.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.