Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. STRING* to LPTSTR

STRING* to LPTSTR

Scheduled Pinned Locked Moved Managed C++/CLI
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bollwerj
    wrote on last edited by
    #1

    Anyone know a simple way to convert a String* variable to a LPTSTR variable?

    D N 2 Replies Last reply
    0
    • B bollwerj

      Anyone know a simple way to convert a String* variable to a LPTSTR variable?

      D Offline
      D Offline
      Dirk Moshage
      wrote on last edited by
      #2

      The easiest way is pStr->GetBuffer(0) Before using you should read the commands in MSDN because you have pay attention by modifying the content of the string.

      B 1 Reply Last reply
      0
      • D Dirk Moshage

        The easiest way is pStr->GetBuffer(0) Before using you should read the commands in MSDN because you have pay attention by modifying the content of the string.

        B Offline
        B Offline
        bollwerj
        wrote on last edited by
        #3

        Dirk, Thanks for the response. I seem to be a bit thick headed, I don't understand what you are suggesting. What data type is pStr? The compiler does not recognize GetBuffer as a member of LPTSTR or of .Net String class. It is a member of .Net MemoryStream class. How do you propose that I do this? What I am doing now to convert a String* variable named line to a LPTSTR (char*) is: char* chars = new char[line->length+1]; for (register i = 0; i < line->length; i++) { chars[i] = (char)line->Chars[i]; } //Add the NULL at the end chars[line->length] = '\0'; The above seems to work but it just seems like a lot of processing to just convert from one data type to another. I'm thinking that there must be a more straightforward way. Thanks John B

        1 Reply Last reply
        0
        • B bollwerj

          Anyone know a simple way to convert a String* variable to a LPTSTR variable?

          N Offline
          N Offline
          Nik Vogiatzis
          wrote on last edited by
          #4

          hi john, try the MS website... (http://support.microsoft.com/?kbid=311259[^]) they provide 3 methods, method 3 being the easiest... cheers nik Nik Vogiatzis PhD Candidate: University of South Australia +++++++++++++++++++++++++++ Developing new generation Traffic Micro-simulation Tools for Traffic Engineers em: nikolaos.vogiatzis@unisa.edu.au

          B 1 Reply Last reply
          0
          • N Nik Vogiatzis

            hi john, try the MS website... (http://support.microsoft.com/?kbid=311259[^]) they provide 3 methods, method 3 being the easiest... cheers nik Nik Vogiatzis PhD Candidate: University of South Australia +++++++++++++++++++++++++++ Developing new generation Traffic Micro-simulation Tools for Traffic Engineers em: nikolaos.vogiatzis@unisa.edu.au

            B Offline
            B Offline
            bollwerj
            wrote on last edited by
            #5

            Nik Thanks for the tip Actually, the only method that worked for me was method 2. Method 3 would not compile. The include altstr.h produced IServiceProvider error. Method 1 compiled OK, but I had to use a LPSTR cast to get it to compile. However, it produced a number (34") regardless of the value of the String* that I fed it. Perhaps there are ways to get methods 1 & 3 to work, but I don't know enough about .Net to figure out how. Cheers and best wishes in your PhD effort. John

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups