Carbon


AECoercePtrProcPtr

Header: AEDataModel.h Carbon status: Supported

Defines a pointer to a function that coerces data stored in a buffer. Your pointer coercion callback routine coerces the data from the passed buffer to the specified type, returning the coerced data in a descriptor record.

typedef OSErr(* AECoercePtrProcPtr) (
    DescType typeCode, 
    const void *dataPtr, 
    Size dataSize, 
    DescType toType, 
    SInt32 handlerRefcon, 
    AEDesc *result
);

You would declare your function like this if you were to name it MyAECoercePtrCallback:

OSErr MyAECoercePtrCallback (
    DescType typeCode, 
    const void *dataPtr, 
    Size dataSize, 
    DescType toType, 
    SInt32 handlerRefcon, 
    AEDesc *result
);
Parameter descriptions
typeCode

The descriptor type of the original data. For a list of AppleScript’s predefined descriptor types, see “Descriptor Type Constants”.

dataPtr

A pointer to the data to coerce.

dataSize

The length, in bytes, of the data to coerce.

toType

The desired descriptor type for the resulting descriptor record. For a list of AppleScript’s predefined descriptor types, see “Descriptor Type Constants”.

handlerRefcon

A reference constant that is stored in the coercion dispatch table entry for the handler. The Apple Event Manager passes this value to the handler each time it calls it. The reference constant may have a value of NULL.

result

A pointer to a descriptor record where your coercion routine must store the descriptor record that contains the coerced data. If your routine cannot coerce the data, return a null descriptor.

function result

A result code. Your handler should return noErr if it successfully handled the coercion, errAECoercionFailed if it can’t handle the coercion and it wants the Apple Event Manager to continue dispatching to other coercion handlers, or a nonzero result code otherwise.

DISCUSSION

To provide a pointer to your coercion callback function, you create a universal procedure pointer (UPP) of type AECoercePtrUPP, using the function NewAECoercePtrUPP. You can do so with code like the following:

AECoercePtrUPP MyCoercePtrUPP;

MyCoercePtrUPP = NewAECoercePtrUPP (&MyCoercePtrCallback);

You can then pass the UPP MyCoercePtrUPP as a parameter to any function that installs or removes a coercion handler, such as AEInstallCoercionHandler. If your application installs the same coercion handler to coerce more than one type of data, you can use the same UPP to install the handler multiple times.

If you wish to call your coercion callback function directly, you can use the InvokeAECoercePtrUPP function.

After you are finished with a coercion callback function, and have removed it with the AERemoveCoercionHandler function, you can dispose of the UPP with the DisposeAECoercePtrUPP function. However, don’t dispose of the UPP if any remaining coercion handler uses it or if you plan to install the coercion handler again.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)