I would change your code to the following;

h = DmGetResource(sysResTAppCode, 7);
if(h != NULL)
{
 void *ftrMem;
 MemPtr procptr;
 //Lock the code resource & get the pointer...
 procptr = MemHandleLock(h);
 if (FtrPtrNew(appFileCreator,myFtrMemFtr,MemHandleSize(h),&ftrMem) ==
errNone)
         DmWrite(ftrMem, 0, procptr, MemHandleSize(h));
 MemHandleUnlock(h);
 DmReleaseResource(h);
 AlmSetProcAlarm((AlmAlarmProcPtr)ftrMem, 0, TimGetSeconds() + 2);
}
If you build your code into a resource, be sure you know what is linked into
the resource and have a proper start address. I usually define the alarm
proc locally, so I don't need a seperate resource.

BTW, since you cannot reference other app code, be aware that some
'switch()' and math code is in the runtime linked with your app, so be
careful not to use them. If you have a lot of work to do in the alarm proc
and would like a more fully featured runtime, then you're better off
building a seperate code resource that includes it's own runtime. I
recommend you not do very much in the alarm proc.

Try the following;

//===========================================================

// If you do not need data in your alarm proc, then leave out
// the MyAlrmProcDataType stuff.

typedef struct
 {
 // data here
 } MyAlrmProcDataType;


// This is the alarm proc that you will copy into feature memory.
// It must not reference globals, statics or any other app code.
static void MyAlarmProc(UInt16 almProcCmd, SysAlarmTriggeredParamType *
pAlarmParam)
 {
 MyAlrmProcDataType *data = (MyAlrmProcDataType*)pAlarmParam->ref;

 if (almProcCmd == almProcCmdTriggered)
  {

  // do your stuff here

  // Free the data structure passed to the proc.
  MemPtrFree(data);
  // Release the feature memory. It's okay because nothing will
  // happen to it until we've returned.
  FtrUnregister(appFileCreator,myFtrMemFtr);
  // Set the alarm as handled.
  pAlarmParam->purgeAlarm = true;
  }
 }


// This is a dummy function to mark the end of alarm proc code above.
static void MyAlarmProcEnd(void)
 {
 }


// This is the alarm proc installer.
Err InstallAlarmProc(UInt32 seconds)
 {
 MyAlrmProcDataType *data;
 UInt32 codeSize;
 void *ftrMem;
 Err err;

 // Calculate size of the alarm proc code.
 codeSize = (UInt32)MyAlarmProcEnd - (UInt32)MyAlarmProc;
 // Allocate feature memory to hold the alarm proc code.
 err = FtrPtrNew(appFileCreator,myFtrMemFtr,codeSize,&ftrMem);
 if (err == errNone)
  {
  // Write the alarm proc code to the feature memory.
  DmWrite(ftrMem,0,MyAlarmProc,codeSize);
  // Allocate a data structure to pass info to the alarm proc.
  // If no data is needed, just leave out the data structure stuff.
  data = MemPtrNew(sizeof(*data));
  if (data)
   {
   // Don't forget this, or the data structure will be freed
   // when the app quits.
   MemPtrSetOwner(data,0);

   // fill the allocated data structure as needed

   // Your alarm will fire immediately if it is set for less
   // than two seconds.
   if (seconds < 2)
    seconds = 2;
   // Set the alarm, passing the data structure address as the ref.
   err =
AlmSetProcAlarm((AlmAlarmProcPtr)ftrMem,(UInt32)data,TimGetSeconds()+seconds);
   }
  // Cleanup if there are any errors.
  if (data == 0 || err != errNone)
   {
   FtrUnregister(appFileCreator,myFtrMemFtr);
   err = appErrorClass+1;
   }
  }
 return err;
 }





On Dec 26, 2007 12:50 AM, Mehul Patel <[EMAIL PROTECTED]> wrote:

> Hi Jeff,
> Thank you for the response...
> I know that the segments may be moved by the OS in order to have efficient
> memory management and this is the reason ProcAlarm fails.
>
> I understand your solution but don't know how exactly copy function to
> feature memory and pass that memory location to AlmSetProcAlarm().
> I tried following but something is wrong here...
>
> h = DmGetResource(sysResTAppCode, 7);
> if(h != NULL)
> {
>  void *ftrMem;
>  void *data;
>  MemPtr procptr;
>
>  //Lock the code resource & get the pointer...
>  procptr = MemHandleLock(h);
>  FtrPtrNew(appFileCreator,myFtrMemFtr,MemHandleSize(h)+10,&ftrMem);
>
>  MemPtrSetOwner(ftrMem, 0);
>  if (!FtrGet(appFileCreator,myFtrMemFtr, (UInt32*)&data))
>          DmWrite(data, 0, procptr, MemHandleSize(h)+1);
>
>  MemHandleUnlock(h);
>  DmReleaseResource(h);
>  AlmSetProcAlarm((AlmAlarmProcPtr)ftrMem, 0, TimGetSeconds() + 2);
> }
> The code resource 7 contains only one function and that function does not
> access any static or global data and also does not point anywhere in my
> application.
>
> Please be kind enough to write few lines of code to help me understand it
> better. Thank you!
>
> Regards,
> Mehul
> --
> For information on using the ACCESS Developer Forums, or to unsubscribe,
> please see http://www.access-company.com/developers/forums/
>



-- 
[Jeff Loucks, Gig Harbor, WA, USA]

-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to