Suppose I have x.dll in C ++ that looks like this:
MYDLLEXPORT const char* f1() { return "Hello"; } MYDLLEXPORT const char* f2() { char* p = new char[20]; strcpy(p, "Hello"); return p; }
Now suppose I want to use this in C #
[DllImport("x.dll")] public static extern string f1(); [DllImport("x.dll")] public static extern string f2();
Is there a way to tell the CLR to take ownership of the string returned from f2 but not f1? The fact is that the fact that the line returned from f1 will eventually be freed, deleted, or something else GC will be equally bad that the line returned from f2 will not. Hope the question was clear. thanks in advance
Armen Tsirunyan
source share