Article View: borland.public.cppbuilder.nativeapi
Article #1115Re: SAPI Failure under Vista - Help!
From: Remy Lebeau (TeamB)
Date: Tue, 23 Oct 2007 16:26
Date: Tue, 23 Oct 2007 16:26
42 lines
2443 bytes
2443 bytes
"JohnC" <jcibulskis@sbcglobal.net> wrote in message
news:471dde5b$1@newsgroups.borland.com...
> BSTR TJMCSUtil::StrToBSTR(String InStr)
There is a much easier way to do that:
BSTR TJMCSUtil::StrToBSTR(const String &InStr)
{
return WideString(InStr).Detach();
}
If you want to use SysAllocString() manually, then use
SysAllocStringByteLen() instead:
BSTR TJMCSUtil::StrToBSTR(const String &InStr)
{
return ::SysAllocStringByteLen(InStr.c_str(), InStr.Length());
}
Or use AnsiString's WideCharBufSize() and WideChar() methods:
BSTR TJMCSUtil::StrToBSTR(const String &InStr)
{
int len = InStr.WideCharBufSize();
BSTR OutStr = ::SysAllocStringLen(NULL, len);
if( OutStr )
InStr.WideChar(OutStr, len);
return OutStr;
}
> pVoice->Speak(TJMCSUtil::StrToBSTR(Words),SPF_DEFAULT,NULL);
That is a memory leak. You are not freeing the BSTR that StrToBSTR() is
returning. That is all the more reason to forget allocating the BSTR
yourself and just let WideString manage it for you automatically:
pVoice->Speak(WideString(Words), SPF_DEFAULT, NULL);
Gambit
Technical Details
Message-ID:
<471e20e3$3@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!transit5.hitnews.eu!hwmnpeer03.ams!news.highwinds-media.com!feed.xsnews.nl!border-2.ams.xsnews.nl!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<471a1686@newsgroups.borland.com> <471cd115$1@newsgroups.borland.com> <471ddb48@newsgroups.borland.com> <471dde5b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6c3b668ca80ad7d9 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: <471a1686@newsgroups.borland.com> <471cd115$1@newsgroups.borland.com> <471ddb48@newsgroups.borland.com> <471dde5b$1@newsgroups.borland.com> Subject: Re: SAPI Failure under Vista - Help! Date: Tue, 23 Oct 2007 09:26:29 -0700 Lines: 44 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: <471e20e3$3@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1193156835 207.178.157.90 (23 Oct 2007 09:27:15 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!transit5.hitnews.eu!hwmnpeer03.ams!news.highwinds-media.com!feed.xsnews.nl!border-2.ams.xsnews.nl!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail