Solved

How do I convert wstring variable to LCPWSTR?

Posted on 2007-11-30
2
2,984 Views
Last Modified: 2013-11-17
Hi, I need to use the MessageBox to output a msg box in my COM component. This requires the message text, the 2nd parm, to be of type LPCWSTR.  My string is in wstring.  How can I convert this to LPCWSTR?  Thank you.
0
Comment
Question by:lapucca
  • 2
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20384725
Just use the 'ca_str()' member, i.e.

wstring wstr = L"test";

LPCWSTR lpcwstr = wstr.c_str();

That's it.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20384730
Err, that should hace read "Just use the 'c_str()' member" of course...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question