Przekazywanie wskaźnika char z C # do C ++ [duplikat]
Możliwy duplikat:
Przekazywanie wskaźnika char z funkcji C # do funkcji c ++
Mam ten problem:
Mam funkcję c ++ z tym podpisem:
int myfunction ( char* Buffer, int * rotation)
Parametr bufora musi być wypełniony znakami spacji (0x20 hex)
W C ++ mogę rozwiązać problem po prostu robiąc to:
char* buffer = (char *)malloc(256);
memset(buffer,0x20,256);
res = myfunction (buffer, rotation);
Próbuję wywołać tę funkcję z C #.
To jest moja deklaracja p / invoke:
[DllImport("mydll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern unsafe int myfunction (StringBuilder Buffer, int* RotDegree);
W mojej klasie C # próbowałem to zrobić:
StringBuilder buffer = new StringBuilder(256);
buffer.Append(' ', 256);
...
myfunction(buffer, rotation);
ale to nie działa ....
Czy ktoś może mi pomóc?
Dzięki.