Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to convert CString to LPCWSTR

Reply
Thread Tools

How to convert CString to LPCWSTR

 
 
月夕
Guest
Posts: n/a
 
      07-05-2009
How to convert CString to LPCWSTR
In my code, the function need a parameter LPCWSTR
And I find this can work

///////////////////////////////////////////////////////////////////////////*//////////////////////////////////////////
CFileFind finder;
BOOL bWorking = finder.FindFile(_T("C:\\*.bmp"));
bWorking = finder.FindNextFile();
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (LPTSTR)(LPCTSTR)
finder.GetFilePath(), 0);
///////////////////////////////////////////////////////////////////////////*//////////////////////////////////////////


why we have to add this two (LPTSTR)(LPCTSTR) casting symbols,why
this
works
and is there any ways more usual.


I was confused by the numerous types in MFC, such as unicode, ANISI,
MultibyteChar and so on
thanks in advance
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-05-2009
* 月夕:
> How to convert CString to LPCWSTR


Neither CString nor LPCWSTR are part of standard C++. I.e. the question is off
topic in this group (see the FAQ for suggestions of more appropriate groups to
post in). However, regarding the code sample below:


> In my code, the function need a parameter LPCWSTR
> And I find this can work
>
> ///////////////////////////////////////////////////////////////////////////*//////////////////////////////////////////
> CFileFind finder;
> BOOL bWorking = finder.FindFile(_T("C:\\*.bmp"));


Three things wrong with the above statement:

1. You're using a 'BOOL' type instead of standard C++ 'bool'.

2. You're using a Hungarian prefix 'b', and the rest of the name is meaningless
and misleading: try to train yourself in choosing meaningful names (e.g. look
at others' code).

3. You're using Microsoft _T, which is only meaningful if you have to use the
MFC library in a DLL *and* support both Windows 9x and modern Windows, which
it's almost guaranteed is not your situation.

As a general observation, it seems that you're employing the
monkey-see-monkey-do approach to programming, just copying and modifying code
snippets you find without understanding any of it.

A better (in the sense of more productive) approach is to understand things.



Cheers & hth.,

- Alf
 
Reply With Quote
 
 
 
 
月夕
Guest
Posts: n/a
 
      07-06-2009
thank you above all, that help a lot.
I found c++ is not only a standard, but also a faith to everyone in
weaving a longlasting software architecture *_^
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      07-06-2009
On Mon, 06 Jul 2009 01:21:30 -0500, Paavo Helde <(E-Mail Removed)> wrote:
> =?UTF-8?B?5pyI5aSV?= <(E-Mail Removed)> kirjutas:
>
>> thank you above all, that help a lot.
>> I found c++ is not only a standard, but also a faith to everyone in
>> weaving a longlasting software architecture *_^


I am not sure what that means, but I am replying to this:

> You are right, for small and dirty hacks one can use Perl, bash shell
> script or any other handy scripting language.


Yeah, but that doesn't mean you aren't allowed to do quick hacks in
C++. There's nothing wrong with that[1]. And "longlasting software
architecture" sometimes mean "wasting time thinking about The
Architecture, when that time was clearly needed for experimentation".

/Jorgen

[1] Except when Perl, Python or shell script is a better fit for the
problem. Which it often is.

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Converting LPWSTR to LPCWSTR dehi@gmx.de C++ 2 02-26-2007 01:11 PM
map and LPCWSTR Vincent RICHOMME C++ 2 02-02-2007 08:38 PM
Java String to LPCWSTR Question res7cxbi@verizon.net Java 6 01-16-2006 12:22 PM
char * convert to LPCWSTR Michael Breidenstein C++ 3 06-27-2005 02:44 PM



Advertisments