accessing string buffer posessed by System::String class directly?

B

Bae,Hyun-jik

Hi,

My managed C++ library frequently takes LPCTSTR from managed exe. Due to the
fact that my library doesn't modify string buffer if its parameter type is
LPCTSTR, it won't be required to copy text data from System::String to
another buffer memory, however, I couldn't find how to let my library access
System::String text buffer directly.

Please reply any answers. Thanks in advance.

Regards,
Hyun-jik Bae
 
T

Tomas Restrepo \(MVP\)

My managed C++ library frequently takes LPCTSTR from managed exe. Due to
the fact that my library doesn't modify string buffer if its parameter
type is LPCTSTR, it won't be required to copy text data from
System::String to another buffer memory, however, I couldn't find how to
let my library access System::String text buffer directly.

Sounds like you're looking for PtrToStringChars(), defined in vcclr.h.

That said, notice this returns a const Char* (i.e. const wchar_t*), so it
would be always equivalent to LPCWSTR. You'll never be able to fully get it
to work naturally for LPCTSTR because it just won't work if you compile for
ANSI/MBCS (since System::Strings are unicode always)
 
J

Jochen Kalmbach [MVP]

Hi Bae!
My managed C++ library frequently takes LPCTSTR from managed exe. Due to the
fact that my library doesn't modify string buffer if its parameter type is
LPCTSTR, it won't be required to copy text data from System::String to
another buffer memory, however, I couldn't find how to let my library access
System::String text buffer directly.

See: Convert from System::String* to TCHAR*/CString
http://blog.kalmbachnet.de/?postid=18

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top