conversion from CFTypeRef to CFStringRef without full expression

Discussion in 'Mac Programming' started by vishal.chauhan, Jun 8, 2009.

  1. vishal.chauhan macrumors newbie

    Feb 4, 2008
    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.

  2. gnasher729 macrumors P6


    Nov 25, 2005
    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?
  3. vishal.chauhan thread starter macrumors newbie

    Feb 4, 2008

    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
    	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.


Share This Page