Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

vishal.chauhan

macrumors newbie
Original poster
Feb 4, 2008
8
0
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
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.

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

macrumors newbie
Original poster
Feb 4, 2008
8
0
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
 

tizz

macrumors newbie
May 20, 2020
1
0
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
in order to print a CFStringRef you should use this
Boolean CFStringGetCString(CFStringRef theString, char *buffer, CFIndex bufferSize, CFStringEncoding encoding);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.