【发布时间】:2017-02-14 04:54:40
【问题描述】:
我将 byte[] 从 C# 传递到 C++ DLL
在 C++ DLL 中,我需要调用一个接受和读取 istream 对象的函数,我打算从 C# 接收 byte[] 作为 char* 并将其转换为 istream,
C++ DLL
extern "C" _declspec(dllexport) bool CheckData(char* data, int dataLength)
C#
[DllImport("example.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool CheckData(byte[] incoming, int size);
public void Process(byte[] bytes)
{
CheckData(bytes, bytes.Length);
}
虽然看起来工作正常,但我发现 byte[] 的等效数据类型在 C++ 中是 unsigned char*,我想改成 unsigned char* 但 C++ 中的大多数 stream 适用于 char* 而不是 @ 987654333@
我想问
1)char*和unsigned char*的数据类型都是1字节,后面发生了什么?如果我继续使用byte[] 和char*,会不会有任何潜在问题?
2) 万一出现问题,我应该如何使用unsigned char*来构造istream对象?
【问题讨论】:
-
拥有它就可以了。
-
你知道后面发生了什么吗?我想了解发生了什么
-
什么都没有发生。实际上有一个重新解释演员表。
标签: c# c++ dll pinvoke marshalling