我有一个用 C++ 编写的函数,带有下一个标题:
void EncodeFromBufferIN(void* bufferIN,int bufferINSize, unsigned char* &bufferOUT, int &bufferOUTSize);
我已经像这样编辑了 .h 和 .cpp 文件,以便能够通过在 C# 中导入 DLL 来调用该函数:
**EncodeFromBufferIN.h**
extern "C" {
__declspec(dllexport) void EncodeFromBufferIN(void* bufferIN, int bufferINSize, unsigned char* &bufferOUT, int &bufferOUTSize);
}
**EncodeFromBufferIN.cpp**
extern void EncodeFromBufferIN(void* bufferIN, int bufferINSize, unsigned char* &bufferOUT, int &bufferOUTSize){
// stuff to be done
}
但现在我的问题是我不知道如何在 C# 中调用该函数。我在 C# 中添加了下一个代码,但不确定如何将参数传递给函数。
[DllImport("QASEncoder.dll")]
unsafe public static extern void EncodeFromBufferIN(void* bufferIN, int bufferINSize, out char[] bufferOUT, out int bufferOUTSize);
bufferIN 和 bufferOUT 应该是字符串,但如果我这样调用函数:
public string prepareJointsForQAS()
{
string bufferIN = "0 0 0 0 0";
char[] bufferOUT;
int bufferOUTSize;
EncodeFromBufferIN(bufferIN, bufferIN.Length, bufferOUT, bufferOUTSize);
}
我收到此错误:“...的最佳重载方法匹配有一些无效参数”。那么应该如何传递参数呢?