convert std:string to LPCTSTR

F

farseer

How can i do this?

i'd like to call the following code:

....
string url = <my urld>;
TCHAR* urlParams = GetParams( );
url.append( (char * ) urlParams );
GotoURL( ( LPCTSTR ) url ); <------THIS IS MY ISSUE
....


static BOOL GotoURL(LPCTSTR lpszUrl)
{
// Try to open hyperlink

SHELLEXECUTEINFO sei;

memset(&sei, 0, sizeof(SHELLEXECUTEINFO));

sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_FLAG_NO_UI;
sei.lpVerb = _T("open");
//sei.lpFile=_T("iexplore.exe");
sei.lpFile = lpszUrl;
sei.nShow = SW_SHOWMAXIMIZED;
//sei.lpParameters=_T("you url here");

return ShellExecuteEx(&sei);
}
 
A

Alf P. Steinbach

* farseer:
How can i do this?

Standard C++ does not have a type called LPCTSTR, and you haven't
defined it.

I.e., you're off-topic in clc++.

Please post your question to e.g. [comp.os.ms-windows.programmer.win32].
 
J

Jim Langston

farseer said:
How can i do this?

i'd like to call the following code:

...
string url = <my urld>;
TCHAR* urlParams = GetParams( );
url.append( (char * ) urlParams );
GotoURL( ( LPCTSTR ) url ); <------THIS IS MY ISSUE

Folling back the definition to LPCTSTR it is a const widechar pointer.

You *may* be able to use url.c_str() which is a const char*, but I'm not
positive. Try microsoft.public.vc.language or another windows platform
specific group for a definitive answer as this question is actually off
topic here (only because LPCTSTR is windows specific )
 
S

shailesh

I guess:

GoToURL (url.c_str()) might work. But off-course it requires that you
are using MBCS and not UNICODE. In UNICODE.

-shailesh.
 
J

Jim Langston

Geo said:
Is it? How can you tell?

In the IDE right click LPCTSTR and click "go to definition" which takes us
to a definition of some other define. Then right click that and go to
definition til you get back to what it unltimately is defined as.
 
J

Jarmo Muukka

farseer said:
How can i do this?

i'd like to call the following code:

...
string url = <my urld>;

If you are writing UNICODE program, then you need to use class wstring.
TCHAR* urlParams = GetParams( );

TCHAR* may be char* or wchar_t* depending on UNICODE definition.
url.append( (char * ) urlParams );

So, if urlParams is UNICODE string, then this does not do what you want.
Avoid casting to wrong type.
GotoURL( ( LPCTSTR ) url ); <------THIS IS MY ISSUE

string class has c_str() method you can call, so just use url.c_str() and do
not cast.
 
F

farseer

Jarmo said:
string class has c_str() method you can call, so just use url.c_str() and do
not cast.

unfortunately, when i tried this, i still get a type conversion error:
"cannot convert parameter 1 from 'const char *' to 'LPCTSTR'"

The solution that worked best for me and that appears will work
irregardless of single or wide chars is...

typedef std::basic_string< TCHAR > tstring;
static tstring SEARCH_URL ( _T( "http://search.yahoo.com/search?p="
) );
...
...
TCHAR* params= GetParams( );
tstring URL ( SEARCH_URL );
URL.append( params );
GotoURL ( URL.c_str( ) );


static BOOL GotoURL(LPCTSTR lpszUrl)
{
...
...
}
 
G

Geo

Jim said:
In the IDE right click LPCTSTR and click "go to definition" which takes us
to a definition of some other define. Then right click that and go to
definition til you get back to what it unltimately is defined as.

No, you're missing the point, the OP's code was incomplete, he could
have a definition of LPCTSTR earlier in his code that could be
anything. It seems you've made some unfounded assumptions, like you've
made above, I may not have and IDE, I may have nothing to click, I
could be typing this on my almost dead VAX terminal, writting my code
in EDT.
 
J

Jim Langston

Geo said:
No, you're missing the point, the OP's code was incomplete, he could
have a definition of LPCTSTR earlier in his code that could be
anything. It seems you've made some unfounded assumptions, like you've
made above, I may not have and IDE, I may have nothing to click, I
could be typing this on my almost dead VAX terminal, writting my code
in EDT.

Oh, well, I actually didn't look at who I was replying to, and thought it
was the OP asking how I did it.

Reguardless, this is windows code, and that's how we can tell how LPCTSTR is
defined.

I think the question you wanted to know was, "how can I tell"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top