in c++ I have such function
extern "C" _declspec(dllexport) uint8* bufferOperations(uint8* incoming, int size)
I am trying to call it from c# like this
[DllImport("MagicLib.DLL", CallingConvention = CallingConvention.Cdecl)]
//[return: MarshalAs(UnmanagedType.ByValArray)]//, ArraySubType=UnmanagedType.SysUInt)]
public static extern byte[] bufferOperations(byte[] incoming, int size);
But I get the Cannot marshal 'return value': Invalid managed/unmanaged type combination
((( The question is - how to marshal this correctly? Thanks for reading my question
byte[] is a .Net array type with known length. You can't marshal byte* to it, because .Net does not know the length of output array. You should try manual marshalling. Replace byte[] with byte*. Then, do like this:
You don't need to use
unsafe contexts
in this case. Just use IntPtr.And then you can use Marshal.Copy to get your byte-array from it.