How to remove this __CFNumber* warning

Zaelsius
Unregistered
 
Post: #1
Hello, I am a noob to Apple's Carbon API. I have source code like this:

.
Code:
CFDictionaryRef desktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
    
CFNumberGetValue( CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
                           kCFNumberIntType,
                           &m_desktopWidth ); // need a cast here..


The problem is that I get the following warning:

Code:
[i]warning: invalid conversion from `const void*' to `const __CFNumber*[/i]

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

NOTE: m_desktopWidth is an int(eger)
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #2
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.
Quote this message in a reply
Zaelsius
Unregistered
 
Post: #3
That code gets me two warnings instead of one Sad
Code:
warning: invalid conversion from `const void*' to `const __CFNumber*'
warning: invalid conversion from `const void*' to `void*'
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #4
Well, m_desktopWidth needs to be a CFNumber, not an integer. Or rather, what you pass to CFGetValue has to be a CFNumber.
Code:
CFNumberRef myVal;
CFDictionaryRef desktopVideoMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
CFNumberGetValue( CFDictionaryGetValue( desktopVideoMode, kCGDisplayWidth ),
                                                   kCFNumberIntType,
                                                   &myVal); // need a cast here..
CFNumberGetValue (myVal, kCFNumberIntType, &m_displayWidth);
Quirky, eh? Wink
Quote this message in a reply
Zaelsius
Unregistered
 
Post: #5
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:

Code:
CFNumberGetValue( [b][color=red](CFNumberRef)[/color][/b]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 !!! Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  NSMutableArray wont let me remove its content Bommbomm 2 6,530 Mar 8, 2011 01:21 PM
Last Post: Bommbomm