I am passing a byte[] from C# to C++ DLL
Inside the C++ DLL, I need to call a function which accept and read istream object, I intend to receive the byte[] from C# as char* and convert it to 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);
}
Although it seems to work fine, I find that the equivalent data type of byte[] is unsigned char* in C++, I thought of changing to unsigned char* but most stream in C++ works on char* not unsigned char*
I would like to ask
1) Both data type char* and unsigned char* are 1 byte, what happened behind? Is there any potential problem if I keep using byte[] with char*?
2) In case there is any problem, how should I use unsigned char* to construct an istream object?