0

I'been developing a library on C# for the last days, and now, I need to build that library into a dll, and use that dll from Qt. The library includes three classes I need to access, and my original idea was to simply build the dll, use dumpcpp to get the headers and use them from Qt along with activeqt, which I have used before.

The problem is that I cannot manage to get the headers from dumpcpp, it fails, returning:

dumpcpp: loading '.\Wrapper.dll' as a type library failed
dumpcpp: error processing type library '.\Wrapper.dll'

The Visual Studio project I'm using is a Class library (.Net Standard), and I'm using building it for x86 architecture. I've seen this link and tried using

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]

with the three classes I need in order to get a COM dll which I suppose must be usable by dumpcpp, but it fails with the same error I mentioned before. Almost every documentation I have found is about using C++ dlls on C#, and there's nothing about using dumpcpp with C# dlls.

Do somebody has any ideas on how to get this dll working with dumpcpp, so that I can use it with Qt? I'd be really grateful.

Thanks a lot!

Edit: In case it helps, here it's the basic structure (without the complex funcionality) of the unique main .cs file the dll includes:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Wrapper
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class Device
    {
        public string host;
        public string username;
        public string password;
        public uint port;

        private bool _serverConnected;
        public uint serverGroupId { get; private set; }
        public uint serverId { get; private set; }
        private object[] _cameraIds;

        public Device(string host, string username, string password, uint port)
        {
            this.host = host;
            this.username = username;
            this.password = password;
            this.port = port;


            this._serverConnected = false;
            Debug.WriteLine("Device Initialized");
        }

        public bool isConnected() => _serverConnected;

        public void onServerConnected(uint serverGroupId, uint serverId)
        {
            Debug.WriteLine("ServerConnectedEventHandler"); // TODO: Remove, just for testing
            _serverConnected = true;
        }

        public void onServerGroupDisconnected(uint serverGroupId)
        {
            Debug.WriteLine("ServerGroupDisconnectedEventHandler"); // TODO: Remove, just for testing

            _serverConnected = false;
        }
    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    class Player
    {
        private Device _device;

        private static readonly int NUM_FRAMES = 10;
        private Frame[] _lastFrames = new Frame[NUM_FRAMES];
        private int _toReadFrame, _toReceivedFrame;

        public Player(Device device)
        {
            this._device = device;
            _toReadFrame = 0;
            _toReceivedFrame = 0;
        }

        public Frame Image()
        {
            Frame tmp = _lastFrames[_toReadFrame];
            _toReadFrame = (++_toReadFrame) % NUM_FRAMES;
            return tmp;
        }

        void FrameAvailableEventHandler(int width, int height, byte[] data)
        {
            _lastFrames[_toReceivedFrame] = new Frame(width, height, data);
            _toReceivedFrame = (++_toReceivedFrame) % NUM_FRAMES;
        }

    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    class Frame
    {
        public int width { get; private set; }
        public int height { get; private set; }
        public byte[] data { get; private set; }

        public Frame(int width, int height, byte[] data)
        {
            this.data = data;
            this.width = width;
            this.height = height;
        }
    }
}
Javierd98
  • 708
  • 9
  • 27
  • Are the classes public? Are the classes in c# the top level class and the top level namespace? – jdweng Dec 18 '20 at 12:23
  • Yeah. The three classes are public, directly inside namespace {} with, all their methods being public too. – Javierd98 Dec 18 '20 at 12:25
  • the error message indicates the library failed not the the methods were not found. Make sure this is on top of the module and you register using step 7 : using System.Runtime.InteropServices; Step 7 is using Net 4.0 so you may need to change net version of 4.0 is not installed. – jdweng Dec 18 '20 at 12:35
  • What do you mean by step 7? I use VisualStudio 2017 so the latest version of .NET Core I can use is 2.2, but on the code, the line "using System.Runtime.InteropServices;" is the first one. In fact, I have edited my question to add the basic structure of my code, so feel free to check it out. Thanks! – Javierd98 Dec 18 '20 at 17:46
  • Step 7 for the answer in your link. – jdweng Dec 18 '20 at 19:49

0 Answers0