我傳遞一個byte[]
從C#到C++ DLL傳字節數組C++ DLL爲char *
裏面的C++ DLL,我需要調用接受和讀取istream
對象的功能,我打算接收所述byte[]
從C#作爲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*
,但大多數stream
在C++工程對char*
沒有unsigned char*
我想請問
1)數據類型char*
和unsigned char*
都是1個字節,後面發生了什麼?如果我繼續使用byte[]
和char*
,是否有任何潛在的問題?
2)如有任何問題,應如何使用unsigned char*
來構造istream
對象?
沒問題,因爲你有它。 –
你知道後面發生了什麼嗎?我想了解發生了什麼 –
沒有什麼事情發生。實際上有一個reinterp演員。 –