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

  • Thread starter Thread starter Bae,Hyun-jik
  • Start date Start date
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
 
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)
 
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/
 
Back
Top