I am completely confused with how to go about calling functions in native dll with array arguments.
Example:
The function is defined in the C# project as:
Your C++ code is broken. The caller allocates the array, and the callee populates it. Like this:
extern "C" _declspec(dllexport) void modifyArray(int* x, int len)
{
for (int i=0; i
As far as your p/invoke call goes, SetLastError
should not be true
. The function is not calling SetLastError
. It should be:
[DllImport("Project2.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void modifyArray(int[] x, int len);