相关疑难解决方法(0)

为C++ DLL实现回调C#函数

我正在为我的C++库编写一个DLL包装器,从C#调用.此包装器还应具有从库调用并在C#中实现的回调函数.这些函数例如将std :: vector <unsigned char>作为输出参数.我不知道如何做到这一点.如何通过回调函数将未知大小的缓冲区从C#传递到C++?

我们来看看这个例子吧

CallbackFunction FunctionImplementedInCSharp;

void FunctionCalledFromLib(const std::vector<unsigned char>& input, std::vector<unsigned char>& output)
{
    // Here FunctionImplementedInCSharp (C# delegate) should somehow be called
}

void RegisterFunction(CallbackFunction f)
{
    FunctionImplementedInCSharp = f;
}
Run Code Online (Sandbox Code Playgroud)

应该如何 CallbackFunction定义以及FunctionCalledFromLib中的代码是什么?

愚蠢的一件事是:如何在C++代码中删除C#创建的缓冲区?

c# c++ interop

4
推荐指数
2
解决办法
9271
查看次数

标签 统计

c# ×1

c++ ×1

interop ×1