大家看见没有,迅雷只能启动一个,这个在代码中间是如何实现的呢,我们来亲自在代码中实践一下。
- #include<windows.h>
- #include<stdio.h>
- int main(int argc,char *argv[])
- {
- HANDLE hMutex;
- DWORD dwErr;
- hMutex=CreateMutex(NULL,
- FALSE,
- "HACK");
- if(hMutex==NULL)
- {
- MessageBox(NULL,"CreateMutex error!",NULL,MB_OK);
- }
- else
- {
- dwErr=GetLastError();
- if(dwErr==ERROR_ALREADY_EXISTS)
- {
- MessageBox(NULL,"Application has already running",NULL,MB_OK);
- ExitProcess(0);
- }
-
- }
- getchar();
- return 0;
- }