Use VB.NET dll methods in Qt

  • I've published a post for this problem a week or so ago, but the topic was unsolved. I have tried numerous things and have a more detailed description of the problem now. Please note, I had 0 experience with DLLs, so solutions below are just my assumption from what I've been able to read online.


    • DLL from a 3rd party that was built in Visual Studios 2015 using Framework .NET 4.0 and coding language VB.NET.
    • List of inputs and outputs to DLL (it's 1 class, with number of inputs, (1) function and number of outputs. I had the excel with inputs and outputs, but also confirmed inside by using .NET Reflector).

    Problem: Using this DLL (VB.NET) in Qt Creator.

    This article here states that there are (2) options:

    1. .NET DLL exposes a COM interface
    2. .NET DLL does not expose COM interface

    Case 1. NET DLL exposes a COM interface
    I downloaded .NET Reflector and it showed in DLL properties "Assembly: <ComVisibility : False>. My one assumption is that this means that DLL does not expose COM interface. But I still continued. What if it IS COM friendly? Then:

    • I would have to "register" the .DLL using Regasm.exe of Microsoft.NET which will result in TLB file (not sure about this)
    • Use Dumpcpp tool (ActiveQT framework) to import TLB library into my .PRO file which is supposedly will have to create header and source files with all the correct namespaces and classes.
    • Then simply use "import" function for the TLB file and start using DLL methods.

    Case 2. .NET DLL does not expose COM interface
    In this case I have to use "CLR" principles, "C++/CLI" wrapping, etc. I don't know anything about this (!?)


    1. Are my assumptions/steps even remotely right? (feel free to destroy my assumptions, I am not married to them at all)
    2. What is exactly needed in order for Regasm.exe to work properly?
    3. Is it necessary to have Visual Studio to create TLB file?
    4. Can you just simply use dumpcpp and "import" after having TLB file to access the methods?
    5. Have anyone had success implementing .NET DLL into Qt?

    I am a mechanical engineer with some knowledge of coding and voluntarily developing this one tool for my company. I would save a lot of headache by just using C# which I assume will make it fairly easy to work with the given DLL, but I spent so much time researching this so it's a deal of principle now to reach the solution :)

    Any help is greatly appreciated.


  • Hi, I think option 1, using Regasm.exe would be your best choice. Regasm.exe will happily wrap any .NET DLL (as long as it is compiled error free) into either some registry entries for COM consumption and/or write a .tlb file for you that Qt's Dumpcpp tool should be able to read.

  • Case 2: Mixing C++/CLI and Qt sometimes introduces unexpected bugs. here you can find a small program that uses .Net API to send emails (I'm not aware of a public C/C++ API for MS Exchange). It builds in Qt creator and it's controlled via sidin/stdout in a QProcess launched by my main application

  • @hskoglund Thank you for the reply.

    1. Will there be any problem if .NET assembly ComVisible property is set to false? (see below, from .NET Reflector)



    TYPELIBS = $$system(dumpcpp -getfile {00062FFF-0000-0000-C000-000000000046})~~

    I assume that the number in {} brackets is an identifier of a TLB library that you get from regasm. Where can I get this number? Is it the same as "Guid" number from the screenshot above? Figured this one out.

    Once again, thank you for your help.

  • @VRonin Thank you for your feedback. The C++/CLI way seems to be more complicated that using dumpcpp tool. However, if dumpcpp doesn't work I will have to use this option.

  • @hskoglund I was able to use RegAsm command on my DLL. It creates a TLB file but I don't think it imports anything from the DLL, because original DLL is 400kB and TLB file is 2kB. Not sure if this is because <Assembly ComVisibility is "false">.

    I was also able to run dumpcpp tool on the generated TLB file and it created header and source file which I can open in QT but they are empty (for the above reason I suspect).

  • Yeah, it seems nowadays the default is to set ComVisibitily to false, because lots of stuff like C# generics do not play well with COM :-(

    So to get some stuff into your TLB file, if you have access the source code of that 3rd party DLL, try prefixing the CLASS statements with <ComVisible(True)> and rebuild the DLL.

  • @hskoglund @VRonin
    Hi there! I finally got the DLL back with <ComVisible> property set to "true". So here is what I did:

    1. Run Regasm.exe on my DLL. My DLL is 386kB and in return I've got 6kB TLB file.
    2. I used dumpcpp function on my TLB file. I've got header and source file as a result.

    In my main project I can open these header and source files, the namespaces were created. I can even see classes announced inside of the header and source files. I know for fact that each class has at least 30 variables (float type) and at least 3-4 functions. I cannot find these anywhere in header or source files.

    So basically I can see announced classes without its methods, although they are definitely Public (checked with .NET Reflector).

    In my main code after including generated .h file Qt recognizes the namespace and class. So for example I can write:
    "DLLNamespace::DLLClass MyClass". But when I try to build the project I get "LNK 2001 Unresolved Link" errors.
    I also tried through pointers "DLLNamespace::DLLClass *Myclass = new DLLNamespace::DLLClass". Same Link errors (something about Metacast and metaobject).

    I believe that TLB file just creates an access to these classes and namespaces, but I have to somehow load the actual DLL to be able to access methods of these classes. Is this correct or am I missing something here? Do I have to INCLUDEPATH the actual DLL in pro file?

    Thank you a ton for all the help, I've gotten this far now thanks to you guys :) Hopefully I will eventually succeed!

Log in to reply