Carbon in Cocoa

I'm trying to use a few carbon functions in cocoa, but can't seem to quite get it to work. The carbon functions are pre-written from Apple and so is the implementation code for cocoa (I'm using their QuickTime code found here: http://developer.apple.com/samplecode/SimpleCocoaMovie/SimpleCocoaMovie.html). My problem is getting it to complile as carbon. According to Apple's documentation here: http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/, Xcode should compile each file based on its extention. The carbon file has a ".c" extension, so it should compile as carbon, but does not. I get something like 13000 errors and I briefly looked through the first few to see what kind of errors they are. All of them are cocoa syntax errors.

I built Apple's sample problem without any problem whatsoever, so I have absolutely no idea what's wrong with my project or where to even begin fixing it. Can somebody give me any suggestions?

Thanks you
 
I'll post the code, but I don't think the problem is the code. I think it has something to do with Xcode itself and not compiling the carbon file as carbon.

Here's the code from the carbon header (from this file: http://developer.apple.com/samplecode/SimpleCocoaMovie/listing5.html):
Code:
NSString *GetMovieTimeScaleAsString(Movie theMovie);
NSString *GetMovieDurationAsString(Movie theMovie);

Here's the code implementing the functions that the header defines (in carbon) (from this file: http://developer.apple.com/samplecode/SimpleCocoaMovie/listing4.html):

Code:
 NSString *GetMovieDurationAsString(Movie theMovie)
{
    StringPtr    movieDurationString = MakeMovieTimeDisplayString(GetMovieDuration(theMovie) / GetMovieTimeScale(theMovie));
    NSString    *movieDurationNSString = [NSString stringWithCString:movieDurationString];
    DisposePtr((Ptr)movieDurationString);
    
    return movieDurationNSString;
}

NSString *GetMovieTimeScaleAsString(Movie theMovie)
{
    StringPtr    timeScaleString = MakeMovieTimeScaleDisplayString(GetMovieTimeScale(theMovie));
    NSString    *timeScaleNSString = [NSString stringWithCString:timeScaleString];
    DisposePtr((Ptr)timeScaleString);
    
    return timeScaleNSString;
}

and here's the code in cocoa that tries to use the carbon functions (from this file: http://developer.apple.com/samplecode/SimpleCocoaMovie/listing3.html):

Code:
- (void)setMoviePropertyWindowControlValues:(Movie)qtmovie
{          
    [movieTimeScale setStringValue:GetMovieTimeScaleAsString(qtmovie)];
    [movieDuration setStringValue:GetMovieDurationAsString(qtmovie)];
}

all of the code was pre-written by Apple and compiles correctly in their example.
 
You need to #import <Carbon/Carbon.h> and add Carbon.framework located in /System/Library/Frameworks to your project.

And if you're using QuickTime code you need to do the same for QuickTime.framework also.
 
oh, i forgot to mention that I have included the frameworks already. i've also already included the headers as follows:

in the "MyMovieController.m" (http://developer.apple.com/samplecode/SimpleCocoaMovie/listing3.html) file which is the cocoa file i'm trying to call the carbon functions from:
Code:
#import "MyMovieController.h"
#include <QuickTime/QuickTime.h>
#include "QTUtils.h"


in the "QTUtils.c" (http://developer.apple.com/samplecode/SimpleCocoaMovie/listing4.html) file where the carbon functions are written:
Code:
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
#include <AppKit/AppKit.h>

#include "QTUtils.h"

as well as in the prefix header file for my cocoa app:
Code:
#ifdef __OBJC__
	#import <Cocoa/Cocoa.h>
	#import <Carbon/Carbon.h>
	#import <QuickTime/QuickTime.h>
	#import <WebKit/WebKit.h>
#endif
 
And you're also linking against each of those frameworks too? What's the first error you see when you compile?
 
I don't think I am, but I'm not sure. I'm still fairly new to programming on a Mac. They are all listed under the "Linked Frameworks" group on the tree in Xcodes. Is there another way to tell if they are linked?

After a closer look, I can see that I was wrong. The carbon file appears to be compiled as carbon, because the errors appear to be cocoa errors. The first error is:

undefined type, found '@class'

When I click on it, it takes me to a line in a file called "NSObjCRuntime.h" that says "@class NSString;". It appears to be the definition for the cocoa NSString class.

I know that changes everything, but I must reiterate the I'm new at this ;)
 
Back
Top