P/Invoke a Function Passed a StringBuilder
- by andrew
in a C# file i have a
class Archiver {
[DllImport("Archiver.dll")]
public static extern void archive(string data, StringBuilder response);
}
string data is an input, and StringBuilder response is where the function writes something
the archive function prototype (written in C) looks like this:
void archive(char * dataChr, char * outChr);
and it receives a string in dataChr, and then does a
strcpy(outChr,"some big text");
from C# i call it something like this:
string message = "some text here";
StringBuilder response = new StringBuilder(10000);
Archiver.archive(message,response);
this works, but the problem, as you might see is that i give a value to the StringBuilder size, but the archive function might give back a (way) larger text than the size i've given to my StringBuilder. any way to fix this?