I've the following signature in C++
bool myFunc(
char* strA,
char* strB,
char* strC,
char* strD,
char* strE,
int lengthA,
int lengthB,
int lengthC,
int lengthD,
int lengthF);
In Unity side I have
[DllImport("myDLL")]
public static extern bool myFunc(
char[] strA,
char[] strB,
char[] strC,
char[] strD,
char[] strE,
int lengthA,
int lengthB,
int lengthC,
int lengthD,
int lengthE
);
However when a string from unity, say ABC
, is passed to the C++ I get something like A\0B\0C\0
. Is there a way to fix this?
Thank you.
Update: Done as @Programmer suggested, doesn't make any difference. Might this be due to how I'm maybe using those functions?
C# :
[DllImport("myDLL")]
static extern bool myFunc(
IntPtr strA,
IntPtr strB,
IntPtr strC,
IntPtr strD,
IntPtr strE,
int lengthA,
int lengthB,
int lengthC,
int lengthD,
int lengthE
);
public unsafe bool myFunc(
byte[] strA,
byte[] strB,
byte[] strC,
byte[] strD,
byte[] strE,
int lengthA,
int lengthB,
int lengthC,
int lengthD,
int lengthE
)
{
IntPtr p1;
IntPtr p2;
IntPtr p3;
IntPtr p4;
IntPtr p5;
fixed (byte* p = strA)
{
p1 = (IntPtr)p;
}
fixed (byte* p = strB)
{
p2 = (IntPtr)p;
}
fixed (byte* p = strC)
{
p3 = (IntPtr)p;
}
fixed (byte* p = strD)
{
p4 = (IntPtr)p;
}
fixed (byte* p = strE)
{
p5 = (IntPtr)p;
}
myFunc(
p1, p2, p3, p4, p5,
lengthA, lengthB, lengthC, lengthD, lengthE);
return true;
}
C++ signature:
bool myFunc(
unsigned char* strA,
unsigned char* strB,
unsigned char* strC,
unsigned char* strD,
unsigned char* strE,
int lengthA,
int lengthB,
int lengthC,
int lengthD,
int lengthE);