Groups | Blog | Home
all groups > dotnet interop > february 2006 >

dotnet interop : String* to string - truncates at 255


S Wheeler
2/6/2006 3:25:54 PM
This may have been addressed previously; if so, please provide a reference
link.

I am trying to convert String* to std:string, something like:

std::string ToCppString(System::String* str)
{
std::string os;
//
if(str == 0) {
return(std::string());
}
System::IntPtr intPtr( Marshal::StringToHGlobalAnsi(str));
char* p = (char*)intPtr.ToPointer();
std::string ret(p);
return(ret);
}


str is a XML String that may be arbitralily large. The problem is that the
char buffer is truncated at 255 chars; I found a post describing this exact
problem in another group, but there were no solutions. I have used similar
methods with BSTR with success, but am unsure why the allocated buffer is
limited to 255 chars nor how to resolve the problem. It works fine for str
less than 255 chars.



Thanks in advance.



S Wheeler
2/6/2006 3:45:17 PM
It's the debugger - sorry, I forgot the debugger only show 255 - when
looking at mem all is fine.... Sorry... :).


[quoted text, click to view]

Mattias Sjögren
2/6/2006 11:23:33 PM
[quoted text, click to view]

Don't forget to free the memory allocated by StringToHGlobalAnsi.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
test
10/18/2006 12:12:42 PM
test
---
AddThis Social Bookmark Button