The actual answer to your question is: No, there is no way to convert a string to an LPCTSTR. The first is an object that is represented by a chunk of memory, the latter is a pointer to such an object.
Now, let's interpret your question as: "I have a string and need an LPCTSTR, e.g. for passing an argument to a function. How can I do that?". Then the problem is solvable and turns out to have to major components:
1) Memory allocation
2) Character representation (8-bit vs. 16-bit)
Let's start with (2). LPTCSTR is defined as pointer to a char string or wchar_t string, depending on your compilation settings (Multi-byte string or Unicode string in your VC++ project settings). If your source string happens to be in the other format, you have to use some conversion mechanism to translate wide characters (16-bit) to 8-bit characters or vice versa. You can use functions like MultiByteToWideChar or its counterpart to do that. Or, if you are using CString, the task may be as easy as writing:
CString s1;
...
CStringA s2 (s1);
If your source string happens to have the "right" character size, you don't have to convert anything. CString has a built-in cast function to "pointer to const char", so you can write
CString s1;
...
LPCTSTR pS2 = s1;
and s1 will give you a pointer to its internal buffer.
If you are using STL::string you must do the cast explicitly by calling the c_str member function, for example:
STL::string s1;
...
LPCTSTR pS2 = s1.c_str();
Now to problem (1), buffer management. If you don't have to convert, because character formats do match, you can simply use a pointer to the existing string buffer, just as shown in the two examples above.
If you do have to convert you need an additional buffer for the conversion result. Again you can use several techniques to acquire such a buffer. In the first example we used another CString to provide the buffer (and used CString's capability to convert string of the other "gender"). You can do equally well with STL::string rsp. STL::wstring. Or if you want to do it all by hand you have to allocate the buffer by
new
or
malloc
.
I know, there are many options and alternatives. If you let us know, which type of string you are using and whether you are compiling for mulit-byte character strings or Unicode and what you want to do with the LPCTSTR we could give some concrete advice on how to proceed.