Re: [Carbon] Using Speech in Cocoa
Re: [Carbon] Using Speech in Cocoa
- Subject: Re: [Carbon] Using Speech in Cocoa
- From: Ali Ozer <email@hidden>
- Date: Mon, 1 Oct 2001 10:09:07 -0700
>
> The easiest way to get a Pascal string from an NSString is to use the
>
> CoreFoundation function CFStringGetPascalStringPtr().
>
>
I'd add
>
SpeakString(CFStringGetPascalStringPtr((CFStringRef)AlarmText,CFStringGetSystemEncoding(
>
)));
>
>
Thanks a lot, I get it now. (I'm not speaking about Pascal)
As Brian Webster pointed out, you should be sure to check for NULL
returns from CFStringGetPascalStringPtr(). This function will return
NULL if it can't return the result immediately; so, if it fails, you
should try to call CFStringGetPascalString(), which might do some
conversion work. If you are not in a performance critical area, you can
just call CFStringGetPascalString() all the time. Or, write a wrapper
which takes a temporary buffer (which the caller should allocate on the
stack), and tries both.
Note that CFStringGetPascalString() might also return NULL if the
conversion can't be done to the specied encoding... At that point
though you're done, unless you want to try other encodings.
The warnings on top of CFString.h are quite useful.
Ali