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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bae,Hyun-jik

    #1

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

    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


  • Tomas Restrepo \(MVP\)

    #2
    Re: accessing string buffer posessed by System::String class directly?

    > My managed C++ library frequently takes LPCTSTR from managed exe. Due to[color=blue]
    > 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.[/color]

    Sounds like you're looking for PtrToStringChar s(), 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)


    --
    Tomas Restrepo
    tomasr@mvps.org



    Comment

    • Jochen Kalmbach [MVP]

      #3
      Re: accessing string buffer posessed by System::String class directly?

      Hi Bae!
      [color=blue]
      > 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.[/color]

      See: Convert from System::String* to TCHAR*/CString


      --
      Greetings
      Jochen

      My blog about Win32 and .NET

      Comment

      Working...