大家好,最近刚开始接触wince下的开发,遇到一些问题,不知如何解决,期待各位高手能给予指点,不胜感激。
下面是一段代码,是关于调用系统函数来实现一个功能,但我看的不是很明白,不知道是什么意思,望有过开发经验的或是对系统函数比较了解的能给我一点意见和启发,谢谢!
[DllImport("coredll.Dll")]
private static extern int GetLastError();
[DllImport("coredll.Dll")]
private static extern int ReleaseMutex(IntPtr hMutex);
[DllImport("coredll.Dll")]
private static extern IntPtr CreateMutex(
SECURITY_ATTRIBUTES lpMutexAttributes,
bool bInitialOwner, string lpName);
[StructLayout(LayoutKind.Sequential)]
public class SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
private const int ERROR_ALREADY_EXISTS = 0183;
public static void Run()
{
IntPtr hMutex = CreateMutex(null, false, "ZJS_FJ");
if (GetLastError() != ERROR_ALREADY_EXISTS)
{
System.Windows.Forms.Application.Run(new FrmWel());
return;
}
else
{
ReleaseMutex(hMutex);
return;
}
}
说明一下,frmwel是新建的一个窗体,相当于登陆一样。
另外,他的这个解决方案好像没有Program.cs那个类,一般windows应用程序在那里面设置起始页面,对吧?可他每个窗体页面好像都有一个应用程序的主入口点,如:
///
/// 应用程序的主入口点。
///
static void Main()
{
Mutex.Run();//mutex就是上面包含run()方法的那个类的名字
Application.Run(new FrmLog(iMenuId)); //frmlog是一个新的窗体
}
基本情况就是这样,我没怎么接触过系统函数,望大家说的时候不要说的太高深,说的清晰明白就可以了。谢谢!