Re: CFStringRef to cstring in c++?
Re: CFStringRef to cstring in c++?
- Subject: Re: CFStringRef to cstring in c++?
- From: Andrew Kimpton <email@hidden>
- Date: Tue, 24 Sep 2002 21:47:39 -0700
On Tuesday, September 24, 2002, at 01:13 AM, robert wrote:
I just want to determine and print the names of the MIDI sources
found by
the system. The MIDIObjectGetStringProperty() function returns the
name
as a CFStringRef (which I learned is also a NSString *). What do I
have
to do, in C++, to get the name in the form of a common C string?
I use something along the following:
CFStringRef pstr;
char *value = (char *) malloc(512);
MIDIObjectGetStringProperty(ref, propertyID, &pstr);
CFStringGetCString(pstr, value, 512, 0);
CFRelease(pstr);
Ofcourse, you'll need to add some errorchecking and perhaps find a way
to
find out the length of the string in 'pstr'; the code above was just a
quick-and-dirty hack :)
I'd encourage anyone to think carefully before just simply converting a
CFStringRef to it's C String counterpart. Ask 'why?' you want the C
String ? If you're looking to display the string there are functions to
draw a CFString (or it's unicode component). If you're looking to store
it as part of a preference or similar then store the unicode version.
etc. If you really want the characters to do some sort of string
processing then think about working with the CFString functions for
string searching and processing.
Whilst I doubt that there any devices right now that use localized
property names surely the whole point of using CFString is that they
could. It's much more friendly to some markets to allow localized
versions of the driver to use translated names to refer to outputs,
inputs or other settings.
Andrew 8-)
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.