0

I'm new to cocoa programming but I picked up a project and keep running into an error. The error is :

"Implicit declaration of function '_CGSDefaultConnection' is invalid in C99"

I google'd it but couldn't find a definite answer as to what was wrong. But from what I can tell, the line cid = (CGSConnectionID)_CGSDefaultConnection(); is not being defined in the correct way.

The full code is below:

#define kIconLevel -2147483628
+ (NSArray*)allIconRects
{
    NSMutableArray *rects = [NSMutableArray array];

    int results[1000];
    int count = -1;

    CGSConnectionID cid;
    cid = (CGSConnectionID)_CGSDefaultConnection();
    CGSGetWindowList( cid, 0, 1000, results, &count );

    int i = 0;
    for (i = 0; i < count; i++) {
        CGWindowLevel level;
        CGSGetWindowLevel( cid, results[i], &level );
        if (level == kIconLevel) {
            NSRect bounds;
            CGSGetWindowBounds(cid, results[i], (CGRect*) &bounds);
            [rects addObject:[NSValue valueWithRect:bounds]];
        }
    }

    return rects;
}

Any help will be greatly appreciated :)

Charlie
  • 11,380
  • 19
  • 83
  • 138

1 Answers1

2

C99 requires functions to be prototyped before being used. As this is a hidden API, you need to tell the compiler to look for it at link time rather than in included header files:

extern CGSConnectionID _CGSDefaultConnection();

http://cocoadev.com/DontExposeMe

Community
  • 1
  • 1
Steve-o
  • 12,678
  • 2
  • 41
  • 60
  • That get's rid of the error, but the next line calls upon the "cid", `CGSGetWindowList( cid, 0, 1000, results, &count );`. So would I need to do something like `cid = extern CGSConnectionID _CGSDefaultConnection();` (which I know throws a parse error. – Charlie Aug 11 '11 at 16:20
  • @Charlie see the usage in the CocoaDev link, you do not use `extern` at the function call, you use it with the function prototype. – Steve-o Aug 12 '11 at 01:13