PDA

View Full Version : How to remove this __CFNumber* warning


Zaelsius
2005.06.03, 10:18 AM
Hello, I am a noob to Apple's Carbon API. I have source code like this:

. CFDictionaryRef desktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );

CFNumberGetValue( CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
kCFNumberIntType,
&m_desktopWidth ); // need a cast here..

The problem is that I get the following warning:


warning: invalid conversion from `const void*' to `const __CFNumber*


I have tried with different casts but I can't get away with the warning. Any suggestion?

NOTE: m_desktopWidth is an int(eger)

MacFiend
2005.06.03, 10:28 AM
Not sure, but perhaps this would work:

int *myPtr = &m_desktopWidth;
CFNumberGetValue( CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
kCFNumberIntType,
(const void*)myPtr );

If that doesn't work, clean targets, rebuild and try again.

Zaelsius
2005.06.03, 10:33 AM
That code gets me two warnings instead of one :(
warning: invalid conversion from `const void*' to `const __CFNumber*'
warning: invalid conversion from `const void*' to `void*'

Fenris
2005.06.04, 12:39 AM
Well, m_desktopWidth needs to be a CFNumber, not an integer. Or rather, what you pass to CFGetValue has to be a CFNumber.

CFNumberRef myVal;
CFDictionaryRef desktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
CFNumberGetValue( CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
kCFNumberIntType,
&myVal); // need a cast here..
CFNumberGetValue (myVal, kCFNumberIntType, &m_displayWidth);

Quirky, eh? ;)

Zaelsius
2005.06.04, 08:53 AM
Thanks a lot Fenris. Yours was not still correct but helped me unveil the mistery.

The call that needs a cast is CFDictionaryGetValue(), so final code looks like this:


CFNumberGetValue( (CFNumberRef)CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
kCFNumberIntType,
&m_desktopWidth );

I tried your code but I was still getting the warning only on the first CFNumberGetValue(), so I suddenly realized that was not the parameter the compiler was complaining about!

Finally I got rid of those warnings !!! :)