Article View: borland.public.cppbuilder.nativeapi
Article #215Re: converting wchar_t * to const wchar_t *
From: Remy Lebeau (TeamB)
Date: Mon, 07 Jul 2008 16:48
Date: Mon, 07 Jul 2008 16:48
30 lines
1863 bytes
1863 bytes
"Sean Farrow" <sean.farrow@seanfarrow.co.uk> wrote in message
news:4870f768$1@newsgroups.borland.com...
> How can I convert wchar_t * to const wchar_t *?
I think you mean the other way around - how to convert a 'const wchar_t*' to
a 'wchar_t*'. The std::wstring::c_str() method returns a 'const' pointer
that you cannot write to.
> I'm trying to use the MultiByteToWideChar function
> with an std::wstring as the output string.
That won't work, for the reason mentioned above. You will have to use a
separate wchar_t[] buffer first, and then copy it to the std::wstring
afterwards, ie:
int len = ::MultiByteToWideChar(CP_ACP, 0, __FUNC__, -1, NULL, 0);
if( len > 0 )
{
std::vector<wchar_t> buffer(len);
len = ::MultiByteToWideChar(CP_ACP, 0, __FUNC__, -1, &buffer[0],
len);
buffer[len] = L'\0';
DragonInfo.FunctionName = &buffer[0];
}
Gambit
Technical Details
Message-ID:
<4872492e$3@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<4870f768$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,42b54d6e10712e77 X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4870f768$1@newsgroups.borland.com> Subject: Re: converting wchar_t * to const wchar_t * Date: Mon, 7 Jul 2008 09:48:28 -0700 Lines: 32 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 207.178.157.90 Message-ID: <4872492e$3@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1215449390 207.178.157.90 (7 Jul 2008 09:49:50 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail