• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Porting AppleEvents code from Carbon to Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: NSString string
  • Next by Date: Re: [newbie] one-to-one relationship both ways
  • Previous by thread: re: stringByTrimmingCharactersInSet bug
  • Next by thread: Re: [newbie] one-to-one relationship both ways
  • Index(es):
    • Date
    • Thread