PDA

View Full Version : conversion from CFTypeRef to CFStringRef without full expression




vishal.chauhan
Jun 8, 2009, 05:08 AM
Dear All,

I want to convert from CFTypeRef to CFStringRef, I am using the following code -

CFStringRef myString = CFCopyDescription (value);

But is gives the string with expression but I want only its value.
If anybody knows how to do that then plz help me out.


Thanks.
Vishal



gnasher729
Jun 8, 2009, 09:36 AM
Dear All,

I want to convert from CFTypeRef to CFStringRef, I am using the following code -

CFStringRef myString = CFCopyDescription (value);

But is gives the string with expression but I want only its value.
If anybody knows how to do that then plz help me out.

I am confused what it actually is that you want to achieve.

"CFTypeRef" is not one specific kind of Core Foundation object, it is more something like "void *"; it says "this is some kind of Core Foundation object, but I don't know which one". So a CFTypeRef could really be a CFStringRef, or a CFNumberRef, or a CFDictionaryRef, or anything else.

So if that CFTypeRef is actually a CFDictionaryRef, just as an example, what would you want as the result?

Or, since getting a CFStringRef is not what you actually want to achieve but only some step on the way, what is it that you actually want to achieve?

vishal.chauhan
Jun 8, 2009, 11:12 PM
Hi,

Thanks for reply.
here is the detailed description what I want to achieve.

I am using the following code to get a volume name from IORegistery.

DASessionRef session = NULL;
DADiskRef disk = NULL;
CFDictionaryRef ddref = NULL;
CFTypeRef val = nil;

session = DASessionCreate(kCFAllocatorDefault);

disk = DADiskCreateFromBSDName(kCFAllocatorDefault,session ,path); ///here path is in the form /dev/rdisk1

ddref = DADiskCopyDescription(disk);
if (! ddref) {
///some message here
}

CFDictionaryGetValueIfPresent(ddref,(kDADiskDescriptionVolumeNameKey),&val);


if(val)
{
CFStringRef myString = CFCopyDescription (val);
const char *VolumeName = CFStringGetCStringPtr(myString, kCFStringEncodingMacRoman);

printf(" %s \n", VolumeName);
}


And I want to print volume name.
But it print a expresssion like <CFString 0x40e310 [0xa080a1c0]>{contents = "Macintosh HD"}

But what actually I want is that it should only print Macintosh HD.

Thanks.
Vishal