Click here to Skip to main content
15,908,775 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Convert CString to const char * Pin
dehseth21-Oct-08 1:42
dehseth21-Oct-08 1:42 
AnswerRe: Convert CString to const char * Pin
Le@rner21-Oct-08 1:55
Le@rner21-Oct-08 1:55 
GeneralRe: Convert CString to const char * Pin
toxcct21-Oct-08 2:00
toxcct21-Oct-08 2:00 
GeneralRe: Convert CString to const char * Pin
Cedric Moonen21-Oct-08 2:04
Cedric Moonen21-Oct-08 2:04 
QuestionRe: Convert CString to const char * Pin
CPallini21-Oct-08 2:40
mveCPallini21-Oct-08 2:40 
AnswerRe: Convert CString to const char * Pin
Mark Salsbery21-Oct-08 5:03
Mark Salsbery21-Oct-08 5:03 
AnswerRe: Convert CString to const char * Pin
Alan Balkany21-Oct-08 4:04
Alan Balkany21-Oct-08 4:04 
NewsRe: Convert CString to const char * Pin
Roger Stoltz21-Oct-08 5:53
Roger Stoltz21-Oct-08 5:53 
Alan Balkany wrote:
Here's a solution I've been using to this problem:


Alan, the problem is not the conversion between char* and const char*.
The problem is that he's building with support for unicode and he's using the ansi version of strcpy(), which of course expects a const char*, but the CString object holds a wchar_t*.
The wide-string version of CString automatically converts to a const wchar_t*, which would be expected by the wide-string version of strcpy(): wcscpy().
Iain explained this in the first reply.

Regarding your suggested macro, I'm surprised to find that the stunt slips through the compiler; converting a const pointer to a non-const pointer....
I tried and actually succeeded to convert a CString object via the CSimpleString::operator PCXSTR(), which returns a const pointer to the string, to a wchar_t* and modify the string. WTF | :WTF:
I didn't think the compiler would let me do that and I'll treat it as a compiler bug. I mean, the whole idea behind a const type is that you're not allowed to modify it....
It's even worse than the const_cast<> keyword.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


QuestionWindows Firewall exception Pin
Krishnakumartg20-Oct-08 23:55
Krishnakumartg20-Oct-08 23:55 
AnswerRe: Windows Firewall exception Pin
Saurabh.Garg21-Oct-08 1:18
Saurabh.Garg21-Oct-08 1:18 
AnswerRe: Windows Firewall exception Pin
User 21559721-Oct-08 1:35
User 21559721-Oct-08 1:35 
QuestionCOM dll registration Pin
Krishnakumartg20-Oct-08 23:44
Krishnakumartg20-Oct-08 23:44 
AnswerRe: COM dll registration Pin
Iain Clarke, Warrior Programmer21-Oct-08 0:05
Iain Clarke, Warrior Programmer21-Oct-08 0:05 
GeneralRe: COM dll registration Pin
Krishnakumartg21-Oct-08 0:26
Krishnakumartg21-Oct-08 0:26 
AnswerRe: COM dll registration Pin
Roger Stoltz21-Oct-08 0:16
Roger Stoltz21-Oct-08 0:16 
GeneralRe: COM dll registration Pin
Krishnakumartg21-Oct-08 0:28
Krishnakumartg21-Oct-08 0:28 
GeneralRe: COM dll registration Pin
Iain Clarke, Warrior Programmer21-Oct-08 1:05
Iain Clarke, Warrior Programmer21-Oct-08 1:05 
AnswerRe: COM dll registration Pin
Roger Stoltz21-Oct-08 2:13
Roger Stoltz21-Oct-08 2:13 
QuestionInterface not registered Pin
CodingLover20-Oct-08 23:36
CodingLover20-Oct-08 23:36 
AnswerRe: Interface not registered Pin
Iain Clarke, Warrior Programmer21-Oct-08 0:07
Iain Clarke, Warrior Programmer21-Oct-08 0:07 
QuestionRe: Interface not registered Pin
Roger Stoltz21-Oct-08 0:10
Roger Stoltz21-Oct-08 0:10 
NewsRe: Interface not registered Pin
CodingLover21-Oct-08 2:40
CodingLover21-Oct-08 2:40 
QuestionRe: Interface not registered Pin
Roger Stoltz21-Oct-08 2:54
Roger Stoltz21-Oct-08 2:54 
NewsRe: Interface not registered Pin
CodingLover21-Oct-08 23:11
CodingLover21-Oct-08 23:11 
AnswerRe: Interface not registered Pin
Roger Stoltz21-Oct-08 23:58
Roger Stoltz21-Oct-08 23:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.