STRING* to LPTSTR
-
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.
-
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.
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
-
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
-
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
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