Cancelling a WM_CLOSE using Application2 of the Smart Device Framework

W

wendelborg

The application I'm working on stores all information in-memory due to
security restrictions. One of the problems we are having is other
programs calling SHCloseApps() to free up memory. This will in extreme
cases shut down our application, which effectively means that all
stored information is lost.

To prevent this from happening we have tried to catch the WM_CLOSE
message coming from SHCloseApps. Catching the message works perfectly
through the Application2 class in OpenNETCF. What doesn't work as well
is cancelling the event, as the application exits anyway.

Can anyone tell me if this happens because of the way SHCloseApps
works? Is for instance TerminateProcess called when the application
doesn't close?

The test program is as follows:

----- Program catching WM_CLOSE -----

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
FilterCloseMsg filterCloseMsg = new FilterCloseMsg();
Application2.AddMessageFilter(filterCloseMsg);
Application2.Run(new Form1());
}
}

public class FilterCloseMsg : IMessageFilter
{
private const int WM_CLOSE = 0x0010;

public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WM_CLOSE:
{
return true;
}
}

return false;
}
}

------ Method called from another application to free memory -----

[DllImport("aygshell.dll")]
public static extern int SHCloseApps(int dwMemSought);

private void buttonCloseApps_Click(object sender, EventArgs e)
{
SHCloseApps(20 * 1048576); // Test: Try to acquire 20 MB of
memory
}



Hope you can help me.

Best regards,
Tommy Wendelborg
 
W

wendelborg

Thanks for the quick response.

Unfortunately I'm still having trouble. I have tested a bit without the
message filter, but my test program still exits using
cancelEventArgs.Cancel set to true.

The simple test solutions can be found here:

http://www.lobotommy.com/WM_CLOSE/Application2Test.zip
http://www.lobotommy.com/WM_CLOSE/Killer.zip

Application2Test is set up to catch both WM_CLOSE and Form.Close(). A
note to the Killer application, my device normally has less than 20 MB
of program memory available. Killer is set up to ask for 20 MB of free
memory through SHCloseApps().

During debug both the message filter and close event approaches fire,
but the application closes down regardless.

Any help will be of great value to us. It seems like other people get
it to work, so it would be very kind if somebody could spot our
mistakes.


Best Regards,
Tommy Wendelborg
 
Joined
Jul 2, 2009
Messages
1
Reaction score
0
Wm_close

Hi Tommy,
I am having difficulty with an application built last year using the Mobile Client Software Factory - there are several large objects in use and the application is constantly being closed without notice by the WM_CLOSE message. Did you find any solution to this at all??

thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top