Porting AppleEvents code from Carbon to Cocoa?
Porting AppleEvents code from Carbon to Cocoa?
- Subject: Porting AppleEvents code from Carbon to Cocoa?
- From: Rustam Muginov <email@hidden>
- Date: Fri, 26 Sep 2003 16:53:28 +0400
Hello all.
I am porting some Carbon code to Cocoa. As I come to AppleEvents, I've
bogged in and unable to find any clues in the documentation. Where are two
parts of the problem.
1. Receiving custom Apple Event from another application.
I've substituted carbon install/remove calls with
"setEventHandler:andSelector:forEventClass:andEventID:" and
"removeEventHandlerForEventClass:andEventID:", this functions allowed me to
decrease code mess a bit.
But inside the handler, I still have the following:
// read carbon AEDesc
const AEDesc *inEvt = [event aeDesc];
// read how many "OSTypes" is in apple event
AEGetParamPtr(inEvt, 'CntI', typeLongInteger, &actType,
&mEnabledItemsCount, sizeof(long), &nActSize);
// release old memory and allocate new
if( mEnabledItems )
delete[] mEnabledItems;
mEnabledItems = new MenuCommand[ mEnabledItemsCount ];
// read "OStypes" from apple event
AEGetParamPtr(inEvt, 'Itms', typeWildCard, &actType, mEnabledItems,
sizeof(MenuCommand) * mEnabledItemsCount, &nActSize);
How could I get rid of Carbon functions and use Cocoa api?
2. Creating and sending the Apple Event
Here I am still using pure Carbon function
static OSStatus SendAE( OSType inAE )
{
OSErr myErr;
AppleEvent myaevent,reply;
AEDesc target;
OSType targetappid;
// The target application
targetappid = 'AdLn';
myErr = AECreateDesc(typeApplSignature,(Ptr)&targetappid,
sizeof(OSType),&target);
if( myErr ) return myErr;
myErr = AECreateAppleEvent( 'AdLn', inAE, &target,
kAutoGenerateReturnID, kAnyTransactionID, &myaevent);
if( myErr ) return myErr;
myErr = AESend(&myaevent,&reply,kAENoReply+kAEAlwaysInteract,
kAENormalPriority, 0, NULL, NULL);
if( myErr ) return myErr;
AEDisposeDesc(&target); // Reclaim the storage
AEDisposeDesc(&myaevent);
return noErr;
}
How can I substitute this with Cocoa calls?
For some reasons, I've failed to find Apple documentations on this topic
Thank you in advance
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.