Maybe I should have put it better as well as I seem to be able to access what I call "Objective C" objects from c++, maybe I am using the incorrect terminology.
I have a test cpp file OSCLog.cpp:
/*
* OSCLog.cpp
* OSCLog
*
* Created by Andrew Capon on 09/04/2008.
* Copyright 2008 CAD Ltd. All rights reserved.
*
*/
#include "OSCLog.h"
#ifdef WIN32
void OSCLog::Start(CADTextView *pTVLog)
{
pTVLog->AppendText("Hello World");
}
#else
void OSCLog::Start(NSTextView *pTVLog)
{
NSString *logStr = [NSString stringWithFormat:@" hello Textview"];
NSRange endRange;
endRange.location = [[pTVLog textStorage] length];
endRange.length = 0;
[pTVLog replaceCharactersInRange:endRange withString:logStr];
endRange.length = [logStr length];
[pTVLog scrollRangeToVisible:endRange];
}
#endif
In XCode I have set this Filetype to sourcecode.cpp.ocjcpp
I have a Objective c controller class defined by OSCLogController.h:
//
// OSCLogController.h
// OSCLog
//
// Created by Andrew Capon on 04/04/2008.
// Copyright CAD Ltd All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "OSCLog.h"
@interface OSCLogController : NSObject
{
// controls on the form
IBOutlet NSTextField *tfIpAddr;
IBOutlet NSTextField *tfPort;
IBOutlet NSTextView *tvLog;
OSCLog *oscLog;
}
// Action to start the logging
-(IBAction)start:(id)sender;
@end
And implemented by OSCLogController.m:
//
// OSCLogController.m
// OSCLog
//
// Created by Andrew Capon on 04/04/2008.
// Copyright 2008 CAD Ltd All rights reserved.
//
#import "OSCLogController.h"
@implementation OSCLogController
-(id)init
{
[super init];
oscLog = new OSCLog();
return self;
}
-(void)dealloc
{
delete oscLog;
[super dealloc];
}
-(IBAction)start:(id)sender
{
oscLog->Start(tvLog);
}
@end
The NSTextView tvLog is passed to the cpp code which uses it to append some test text to the TextView.
This all works and is what I was after as the cpp code is using objective c classes (or what I call objective c classes!).
As you can see I am just using a WIN32 define to switch between WIN32 and OSX, I am really after a define like
_OBJC_ for objective c++ to use as the code needs to support more than just two platforms.
Cheers
Andy
Message was edited by: AndrewCapon
Message was edited by: AndrewCapon