Importing a Managed DLL into Qt C++ Project



  • Hi,

    I have a "managed" DLL from Newport for a Cornerstone™ 130 1/8 m Monochromator device.
    How can I import this managed DLL into my Qt C++ project, I prefer to code in Qt Creator? I believe it is a .NET managed DLL.
    I do not have header files or etc, only the single DLL file.
    Also, how do I find out what functions I can call using this DLL and how to call those functions?

    Example code would be appreciated!

    Thanks



  • Hi, if the DLL is intact then it's (relatively) easy to find what the functions in it are. If you have Qt installed with Visual Studio (not MinGW) then you can do like this:
    (Googled for that Newport/Cornerstone DLL, I'm guessing it's called CyUSB.dll :-)

    Start a Visual Studio developer cmd prompt.
    Cd to where CyUSB.dll is
    TLBEXP CyUSB.dll

    This will give you a CyUSB.tlb which you can #import into your Qt app:
    Start an empty Widgets app in QtCreator. In mainwindow.cpp insert
    @
    #import "c:/DirToTheTlb/CyUSB.tlb"
    @

    Build the app, open the debug build directory (assuming you built in debug mode) and open the cyusb.tlh file in Notepad, you'll see the API.

    To actually call, easiest is to register the CyUSB.dll for COM and use Qt's pretty good COM support.



  • Can you provide an example/screenshot of what the contents of the generated .tlh file look like in this case?

    When I tried it (I did use the MinGW version, I got a TLH file with the following contents.

    // Created by Microsoft (R) C/C++ Compiler Version 12.00.31101.0 (b530d70d).
    //
    // d:\program files\new focus\new focus picomotor application\bin\build-trymaketlh-desktop_qt_5_10_1_msvc2013_64bit-debug\debug\cmdlib8742.tlh
    //
    // C++ source equivalent of Win32 type library D:\program files\New Focus\New Focus Picomotor Application\Bin\CmdLib8742.tlb
    // compiler-generated file created 09/26/18 at 10:08:05 - DO NOT EDIT!

    #pragma once
    #pragma pack(push, 8)

    #include <comdef.h>

    namespace CmdLib8742 {

    //
    // Forward references and typedefs
    //

    struct __declspec(uuid("8e4e74aa-7e10-43ad-9995-9c56483422ea"))
    /* LIBID */ __CmdLib8742;

    } // namespace CmdLib8742

    #pragma pack(pop)



  • Hi, sorry I don't have that .dll but here is one example


Log in to reply
 

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