hMutex = CreateMutex( NULL,FALSE, "wg");
if (hMutex == NULL)
{
printf("CreateMutex error: %d/n", GetLastError());
}
::WaitForSingleObject(hMutex,INFINITE);
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO si;
unsigned long exitCode;
si.cb=sizeof(STARTUPINFO);
si.lpReserved=NULL;
si.lpDesktop=NULL;
si.lpTitle=NULL;
si.dwFlags=STARTF_FORCEONFEEDBACK|STARTF_USESHOWWINDOW;
si.wShowWindow=SW_SHOW;
si.cbReserved2=0;
si.lpReserved2=NULL;
if( !CreateProcess((LPTSTR)(LPCTSTR)::StaticLocation, // No module name (use command line).
NULL, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&ProcessInformation ) // Pointer to PROCESS_INFORMATION structure.
)
{
//::CloseHandle(ProcessInformation.hThread);
// ::WaitForSingleObject(hProcess,INFINITE);
}
do
{
GetExitCodeProcess(ProcessInformation.hProcess,&exitCode);
Sleep(10);
}
while(exitCode == STILL_ACTIVE);
ReleaseMutex(hMutex);
简单的形式可以如下表示:
WaitForSingleObject(。。。)
。
。
。
ReleaseMutex(hMutex);