conversion from CFTypeRef to CFStringRef without full expression

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

  1. macrumors newbie

    Joined:
    Feb 4, 2008
    #1
    Dear All,

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

    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
     
  2. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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. thread starter macrumors newbie

    Joined:
    Feb 4, 2008
    #3
    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.

    Code:
    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
     

Share This Page