M
MRe
Hi,
I have a C++ function that takes an allocated char* array in, which it
will copy into, and return. I need to be able to access what was copied into
this array in a csharp program. So far I have this...
C++
void test(char* pOut)
{ CopyMemory(pOut, "abc", 3);
}
C#
[DllImport("test.dll", CharSet=CharSet.Auto)]
private static extern void test([MarshalAs(UnmanagedType.LPStr)] out string
Result);
public string RunTest()
{
StringBuilder sb = new StringBuilder(3, 3);
string Buffer;
// Create space in string - is there a better way to do this?
for(int Index = 0; Index < 3; Index++)
sb.Append(' ');
Buffer = sb.ToString();
test(out Buffer);
return Buffer;
}
But all I get is a System.NullReferenceException.
What's going on please?
Thank you,
Regards,
Eliott
I have a C++ function that takes an allocated char* array in, which it
will copy into, and return. I need to be able to access what was copied into
this array in a csharp program. So far I have this...
C++
void test(char* pOut)
{ CopyMemory(pOut, "abc", 3);
}
C#
[DllImport("test.dll", CharSet=CharSet.Auto)]
private static extern void test([MarshalAs(UnmanagedType.LPStr)] out string
Result);
public string RunTest()
{
StringBuilder sb = new StringBuilder(3, 3);
string Buffer;
// Create space in string - is there a better way to do this?
for(int Index = 0; Index < 3; Index++)
sb.Append(' ');
Buffer = sb.ToString();
test(out Buffer);
return Buffer;
}
But all I get is a System.NullReferenceException.
What's going on please?
Thank you,
Regards,
Eliott