Multi-segment apps and often C++ apps of any size both utilize jump tables
in an initialized data segment. Or, if your alarm handler in your app
references any other functions or global data, then you may/will have
problems. There will be references to data segments that probably
don't exist. The same applies to global or static variables, which also
require an allocated data segment.

Some reasons it may occassionally work;

1. If your app is the current app, then the  data segment exists .

2. If your app was recently the current app, then the data segment, while
not currently allocated, may still exist in residual form. However, the
registers that should be pointing to the data segment most likely no longer
point to you segment, but to the segment allocated to the current app (not
yours).

3. If your app has not run since reset, then the expected data segment and
register values will not exist in any form.

There are hooks and hacks to initialize the required data, but there may be
easier ways to do what you need. It depends on what you need to do in
response to the alarm.

In your case, your app is not the current app and the device is sleeping, so
I presume you want the alarm to wake the device and trigger some
functionality within your app. You are using a proc alarm, so I presume you
do not want the screen to light.

Any resource to be called asynchronously will need to be locked down so the
address remains valid. Remember, however, that if it is part of your
segmented or C++ app, it will probably need an initialized data segment.

Instead, I usually set aside a static function that does not access any
static or global variables, and does not reference any of the rest of the
app. To avoid locking down resources, I copy the function into a feature,
and use it from the feature. If it needs any data, I allocate a structure on
the heap, set the owner to 0 so it doesn't go away, fill it with the needed
data and then pass the address as the user data pointer through the alarm
call (the same thing can be done for a system notifications).

Remember, that when the function has completed it's mission, it must free
the data structure passed to it and then unregister the feature, thus
disposing of itself.

On Dec 23, 2007 11:52 PM, Mehul Patel <[EMAIL PROTECTED]> wrote:

> Hi,
>
> My application has 7 segments.. 7th segement is newly created segment in
> order to solve the problem. I have put the function in this new 7th segment.
> It contains only one function which I will pass in AlmSetProcAlarm().
>
> When I get sleep request notification, I lock this new code resource using
> following code and call AlmSetProcAlarm()...
>
> h = DmGetResource(sysResTAppCode, 7);
> if(h != NULL)
> {
>  MemHandleSetOwner(h, 0);
>  MemHandleLock(h);     //Lock the code resource...
>  DmReleaseResource(h);
>
>  AlmSetProcAlarm(PowerProc, 0, TimGetSeconds() + 5);
> }
>
> But it gives me Memory write error... After making this change atleast the
> procedure gets called everytime...
>
> My first segment is 59K and if I put "PowerProc" function in the first
> segment and call AlmSetProcAlarm() it works the first time but not the
> second time.
>
> Please provde some hint...
>
> Regards,
> Mehul Patel
>  --
> 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