[futurebasic] Re: [FB] AppleEvent handling

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Tue, 7 Jun 2011 13:45:15 +1200
Brian S wrote:

>> I need my current FB4 app which does send and receive AppleEvents,  to send a CFStringRef to a new FB5 app and then it sends back a reply message to my POS software.
> The supporting code for sending an Apple Event ( i.e. SendAppleEvent ) uses pascal strings.


SendAppleEvent sends any number of bytes. Only the target process name must be a Pascal string.

>  You won’t be able to use this FB statement with a CFString

True, if you send a CFStringRef to another process, it cannot make sense of it because the address spaces are not shared.
You have to obtain the CFString's data bytes and send them.

// find the size
dim as CFIndex    dataSize
fn CFStringGetBytes( cfString, fn CFRangeMake( 0, fn CFStringGetLength( cfString ) ), _kCFStringEncodingUTF8, 0, _false, 0, 0, @dataSize ) 
// allocate buffer
dim as pointer    dataPtr
dataPtr = fn malloc( dataSize )
// read bytes into buffer
fn CFStringGetBytes( cfString, fn CFRangeMake( 0, fn CFStringGetLength( cfString ) ), _kCFStringEncodingUTF8, 0, _false, #dataPtr, dataSize, 0 ) 
// send AE
SendAppleEvent _"XXXX", _"YYYY", dataPtr, dataSize, "ToWhomItMayConcern"
// clean up
free( dataPtr )

Robert P.