473,900 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert std:string to LPCTSTR

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

SHELLEXECUTEINF O sei;

memset(&sei, 0, sizeof(SHELLEXE CUTEINFO));

sei.cbSize = sizeof(SHELLEXE CUTEINFO);
sei.fMask = SEE_MASK_FLAG_N O_UI;
sei.lpVerb = _T("open");
//sei.lpFile=_T(" iexplore.exe");
sei.lpFile = lpszUrl;
sei.nShow = SW_SHOWMAXIMIZE D;
//sei.lpParameter s=_T("you url here");

return ShellExecuteEx( &sei);
}

May 30 '06 #1
10 25506
* 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.program mer.win32].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 30 '06 #2
farseer wrote:
How can i do this?

i'd like to call the following code:
snip incomplete, platform-specific code<


http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Luke

May 30 '06 #3

"farseer" <fa*****@optonl ine.net> wrote in message
news:11******** *************@j 73g2000cwa.goog legroups.com...
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.publi c.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 )
May 30 '06 #4
I guess:

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

-shailesh.

May 30 '06 #5
Geo

Jim Langston wrote:
"farseer" <fa*****@optonl ine.net> wrote in message
news:11******** *************@j 73g2000cwa.goog legroups.com...
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.


Is it? How can you tell?
You *may* be able to use url.c_str() which is a const char*, but I'm not
positive. Try microsoft.publi c.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 )


May 30 '06 #6

"Geo" <gg@remm.org> wrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...

Jim Langston wrote:
"farseer" <fa*****@optonl ine.net> wrote in message
news:11******** *************@j 73g2000cwa.goog legroups.com...
> 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.


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.
May 31 '06 #7
"farseer" <fa*****@optonl ine.net> wrote in message
news:11******** *************@j 73g2000cwa.goog legroups.com...
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.
static BOOL GotoURL(LPCTSTR lpszUrl)

May 31 '06 #8

Jarmo Muukka wrote:
string class has c_str() method you can call, so just use url.c_str() and do
not cast.
static BOOL GotoURL(LPCTSTR lpszUrl)


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_stri ng< TCHAR > tstring;
static tstring SEARCH_URL ( _T( "http://search.yahoo.co m/search?p="
) );
...
...
TCHAR* params= GetParams( );
tstring URL ( SEARCH_URL );
URL.append( params );
GotoURL ( URL.c_str( ) );
static BOOL GotoURL(LPCTSTR lpszUrl)
{
...
...
}

May 31 '06 #9
Geo

Jim Langston wrote:
"Geo" <gg@remm.org> wrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...

Jim Langston wrote:
"farseer" <fa*****@optonl ine.net> wrote in message
news:11******** *************@j 73g2000cwa.goog legroups.com...
> 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.


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.


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.

May 31 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
16449
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
2
12211
by: Abhishek | last post by:
how to do convert a std::string to LPTSTR (chat *) datatype regards Abhishek
10
10150
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's Appendix D recommendation won't compile in Microsoft VC++ 6.0). My question is in reference to MultiByte Character Sets. Will this code perform as expected? I understand every problem has a simple and elegant solution that is wrong.
3
40746
by: timor.super | last post by:
Hi group, how to convert a string to a vector of unsigned char ? I used to iterate trough the string to set the vector, but I think this is not the best way to do this. I'm a beginner with the STL How about allocating the vector ? should I know before the size ? And I would like to do then opposite conversion, from an unsigned char
3
11424
by: rsennat | last post by:
Hi, Converting enum to strings is simple. Just we can use the enum as the i ndex to get the string from an array of strings. But how do I convert string to enum. Should I need to compare with every string in the array and return the enum when it matches. Whats the efficient way to do this? Thanks rsennat
2
8498
by: Man4ish | last post by:
How can we convert std::string into basic string?
3
7026
by: BoneKeeper | last post by:
i need help to convert this: char Pointer; GetPrivateProfileString("GENERAL","PointerName",NULL, Pointer, 254,"./Settings.ini"); after i read the value of the setting file i can't convert it to DWORD, need help with this
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10866
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6082
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4301
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.