🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1422

Re: Convert AnsiString to a wchar_t

#1422
From: Remy Lebeau (TeamB)
Date: Wed, 22 Aug 2007 19:50
35 lines
1954 bytes
"Wayne Smith" <wsmith@epgins.com> wrote in message
news:46cc7064$1@newsgroups.borland.com...

> I am including my AnsiString. How would you convert it to a wchar_t?

You can use the WideString class, like Damon suggested, ie:

    WideString temp = "c:\\scanexam\\" + ebDlrNmbr->Text.Trim() + "_" +
newnumber.Trim() + ".jpg";

Or:

    AnsiString asTemp = "c:\\scanexam\\" + ebDlrNmbr->Text.Trim() + "_" +
newnumber.Trim() + ".jpg";
    WideString wTemp = astemp;

WideString is a wrapper for a BSTR, which is based on wchar_t.  As such, it
can be used anywhere a wchar_t* is expected.

If you don't want to use the WideString class, then you need to allocate
your own wchar_t buffer that is large enough to convert the AnsiString into,
ie:

    AnsiString asTemp = "c:\\scanexam\\" + ebDlrNmbr->Text.Trim() + "_" +
newnumber.Trim() + ".jpg";

    int iSize = asTemp.WideCharBufSize();
    wchar_t *wTemp = new wchar_t[iSize];
    asTemp.WideChar(wTemp, iSize);
    // use wTemp as needed...
    delete[] wTemp;


Gambit
Technical Details
Message-ID: <46cc9395$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46cc6c77$1@newsgroups.borland.com> <46cc6e81$1@newsgroups.borland.com> <46cc7064$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d7a8a86c422cc4e7
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <46cc6c77$1@newsgroups.borland.com> <46cc6e81$1@newsgroups.borland.com> <46cc7064$1@newsgroups.borland.com>
Subject: Re: Convert AnsiString to a wchar_t
Date: Wed, 22 Aug 2007 12:50:24 -0700
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.29.61
Message-ID: <46cc9395$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1187812245 75.83.29.61 (22 Aug 2007 12:50:45 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail