As the title suggests I would like to let a string array be described in a function which is in a C++ DLL.
In my actual attempt it runs without exception, but my strArray does not contain any objects after the C++ Function call.
My C# Code:
var strArray = new StringBuilder[100];
for (int i = 0; i < strArray .Length; i++)
{
strArray[i] = new StringBuilder(50);
}
modifyStringInCpp(strArray);
[DllImport(DllFilePath, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private extern static void modifyStringInCpp(StringBuilder[] strA);
My C++ Code:
extern "C" {
__declspec(dllexport) void __cdecl modifyStringInCpp(char** strA)
{
for (size_t i = 0; i < 100; i++)
{
strcpy(strA[i], "testString");
}
}
}
What do I need to change?
charwill convert safely from a .NET string which consists of two-byte chars (IIRC).StringBuilder[]:-( I thought it would work