Hey, this is rigth. But my problem is when i pass by reference a
std::string to an old-style DLL. It writes the result in the pointer,
not in the buffer, then the buffer hold no data(unitialized data), I
call c_str() an retrieves the data in the buffer with bad_data. Is there
a way I can obtain the pointer?
Thanks a lot.


-----Mensaje original-----
De: dotnet discussion [mailto:[EMAIL PROTECTED]] En nombre de
Tomas Restrepo
Enviado el: jueves, 25 de abril de 2002 16:37
Para: [EMAIL PROTECTED]
Asunto: Re: [DOTNET] MC++: string to System::String

Miguel,
> Thanks, this is the way it works. But now, I have another problem. I惴
> calling a function in an API, that have the next signature:
>
> void function1(out std::string* version);
>
> If I debug and see the value in the Watch window, I see the next
version
> returned value:
>
>         version
>                _Bx
>                 [+] _Buf
>                [+] _Ptr  <- The function return the value here
>
> When I call version.c_str(), I obtain a pointer to the buf, that is
like
> a char[], but not to the ptr where the function copies the data.

You're not quite right. It's just that the std::strng implementation on
VC++.NET is quite different. Now, it uses a union between a char[16] and
a
char*. If the string it holds is less than 15 chars in length, it's held
in
the char array in-place, saving an allocation. Only if it's larger will
an
external buffer be allocated on the heap and a pointer to it stored in
_Ptr.
Regardless of that, you can be sure string::c_str() will return a
pointer to
the actual storage of the string.

--
Tomas Restrepo
[EMAIL PROTECTED]

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to