利用信號量機制來完成 防止一個程序被多次運行 的代碼
#include "windows.h"#include <iostream.h>
int main(int argc, char* argv[])
{
?HANDLE hMutex=CreateMutex(NULL,TRUE,"test");
?if (hMutex)
?{
??if (ERROR_ALREADY_EXISTS==GetLastError())
??{
???MessageBox(NULL,"already running","",MB_OK);
???return 0;
??}
?}
?while (1)
?{
?}
?
?return 0;
}
posted on 2006-08-30 20:48 bo 閱讀(1422) 評論(1) 編輯 收藏 引用 所屬分類: OS