Hi,guys. Here is my qustion, how can i restrict an application to be run with only one instance on WinCE platform ?
I wrote an application for PDA,with WinCE 5.0 installed in. And i want to make it run with only one instance,it means,if the application is running ,another instance of it should not be started again.
I tried with some APIs,such as,FindWindowEx,CreateMutex,OpenMutex, but there are no 'kernerl32.dll' and 'user32.dll' files on the platform.
Loading
Sam HobbsPosted Oct 31, 2010, 10:07 PM
Note that there are three possible requirements; one is to do as you say, not alllow additional instances. Another is to activate the first instance from additional instances before exiting. A third is to pass command-line parameters from additional instances.
Kevin LiaoPosted Nov 1, 2010, 2:52 AM
Though , there are no 'kernel32.dll' and 'user32.dll' on WinCE ,we can still use 'coredll.dll' instead, and here is the solution i take finally,as :
static class Program
{
#region WinCE Platform,restrict multi-instance of application,by kevin
[DllImport("coredll.dll")]
private static extern bool ShowWindow(System.IntPtr hWnd, int cmdShow);
[DllImport("coredll.dll")]
private static extern bool SetForegroundWindow(System.IntPtr hWnd);
[DllImport("coredll.dll")]
public static extern System.IntPtr FindWindowW(string strclass, string strname);
public static Boolean IsApplicationRunning(string Caption)
{
System.IntPtr AppHandle = FindWindowW(null, Caption);
if (AppHandle.ToInt32() > 0)
{
return true;
}
return false;
}
public static void BringAppToTop(string Caption)
{
System.IntPtr AppHandle = FindWindowW(null, Caption);
if (AppHandle.ToInt32() > 0)
{
SetForegroundWindow(AppHandle);
}
}
#endregion
///
/// application entry point
///
[MTAThread]
static void Main()
{
if (Program.IsApplicationRunning("LogIn") == true)
{
MessageBox.Show("Application is running...");
Program.BringAppToTop("LogIn");
return;
}
else
{
Application.Run(new FLoginPDA());
}
}
}