Calling a Code Resource
Calling a Code Resource
// Calling a Code Resource
// The following code illustrates how to call a
// code resource. The code resource that we
// are calling is given at the end
// Assuming inclusion of
typedef void (*MyProcPtr) (int); // Define a procedure pointer
// for the code resource
void DoError (OSErr err);
main ()
{
Handle myCRHandle;
ProcPtr myCRPtr;
int integerParam;
myCRHandle = GetNamedResource ('ALCT', "\pmyBeep");
if (myCRHandle == nil)
DoError (ResError());
else
{
HLock (myCRHandle);
(* (MyProcPtr) (*myCRHandle)) ( integerParam);
HUnlock (myCRHandle);
}
}
/*********************************************
Here is the code resource that we're calling
void main (int i)
{
int j;
for (j = 0; j < i; j++)
SysBeep (5);
}
**********************************************/