c# - 在 Qt 中使用带有 dumpcpp 的 C# 库
问题描述
最近几天我一直在 C# 上开发一个库,现在,我需要将该库构建到一个 dll 中,并使用 Qt 中的该 dll。该库包括我需要访问的三个类,我最初的想法是简单地构建 dll,使用 dumpcpp 获取标头并从 Qt 中使用它们以及我之前使用过的 activeqt。
问题是我无法从 dumpcpp 获取标头,它失败了,返回:
dumpcpp: loading '.\Wrapper.dll' as a type library failed
dumpcpp: error processing type library '.\Wrapper.dll'
我正在使用的 Visual Studio 项目是一个类库(.Net 标准),我正在为 x86 架构构建它。我看过这个链接并尝试使用
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
使用我需要的三个类来获取我认为必须由 dumpcpp 使用的 COM dll,但它失败并出现我之前提到的相同错误。我发现的几乎所有文档都是关于在 C# 上使用 C++ dll 的,并且没有关于将 dumpcpp 与 C# dll 一起使用的内容。
有人对如何让这个dll与dumpcpp一起工作有任何想法,以便我可以将它与Qt一起使用吗?我会很感激的。
非常感谢!
编辑:如果有帮助,这里是 dll 包括的唯一主 .cs 文件的基本结构(没有复杂的功能):
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;
}
}
}
解决方案
推荐阅读
- flutter - 等待异步 forEach 完成所有迭代,然后在 Dart 中收集数据
- jekyll - 根据帖子中的变量防止页面最终出现在站点地图中 - Jekyll
- sql - 分层查询中的排序问题
- directory - 用于比较文件夹集、它们的名称和它们的内容以识别差异的工具?
- typescript - 非空断言运算符仍然引发编译时错误
- python - 如何在列名属于日期时间 dtypes 的数据框中选择列?
- javascript - 本地存储中的购物车与mysql连接
- javascript - 颜色指针 HTML5,mouseup 事件
- c# - 如何在 C# 中将来自 api 的响应内容转换为 pdf?
- sql - 使用序号引用按大量列分组