Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have small doubt,
I am having function call from C# managed world to C unmanaged code base..

C# Code
C#
Boolean ChsarpFunction(StringBuilder sb) {
int size;

return GetFormattedString(sb,size);
}

[DllImport(MYDLL, CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false)]
[return: MarshalAs(UnmanagedType.U1)]
... Boolean GetFormattedString( [MarshalAs(UnmanagedType.LPStr)] StringBuilder value, int size);


C Code
bool GetFormattedString (char *str, int* size) {
..
..
strcpy(str,result);
*size = strlen(str);
return (*size > 0); // some result of 0 or 1
}

I don't know or want to set the size for the StringBuilder, What kind of string is optimal to pass by reference.(performance wise)
Any ideas or experience is much appreciated.

Thanks,
Posted
Updated 20-Jan-12 8:22am
v2

1 solution

hummm the StringBuilder can't be tratead as pointer, refer to the StringBuilder Class definition in MSDN, but you can convert the string builder content to a String Object with the ToString() Method, a simply Len to the String Object will give u the size that u're finding.

Good Luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900