I remember that my friend came to me and asked me how I can ban my program overlap in Win95.
I gave him a piece of code, and he went back in the sky.
Now take the code out, everyone share
// Use a method of establishing a mutex to detect multiple instances
Handle Hmymutex = Createmutex (Null, False, "MyMutex"); // "MyMutex" is the identifier of your program, can change DWORD ERRCODE = GetLastError ();
IF (errcode == error_already_exists) {MessageBox (NULL, "Old Example, Abort", "- Notice!", MB_OK | MB_TOPMOST); EXITPROCESS (NULL);} // end of mutual exclusion detection
Add it to the frame that I did yesterday, the winmain function started. See "NO MFC programming 01 - the most streamlined Win32 program" http://www.9cbs.net/develop/read_article.asp?id=15167
Analysis of principles: (I originally wanted to collect, but I saw that the article is too short)
The CreateMutex function creates a mutual exclusion called "mymutex" (don't ask me what is used)
GetLasteError function gets the burst of creation process
The first case: There is no instance before running, and the new "MyMutex" is successful. ("MyMutex" survival is ended from this program instance)
The second case: There is an example in which it is running, and it is found that there is a mutex called "mymutex", which is used. But GetLastError still knows.
The process caused by the second case: Of course, the second example of the exit program, what is the two in the same version WinAmp?
Q: Is there a third case? (Don't tell you)
(There is an advertisement word: "I don't think I am different, because I am unique")
Don't say nonsense! September 28, 2002 AM 9:43
-------------------------- Attach yourself:
Features: No arrival, just arrived to Miqi, voice slightly magnetic, character cheerful, a bit of naughty, a little smart, preamble ... Maximum hobby: playing video games (dream development of ONI cable version, did not play ONI? Ohhh!) The compiler: VC DX_SDK API (称 VC ) recently hangs: Do you believe? Moon soil sample confirmed that the moon has existed before forming the solar system ... currently liked: Chen Mei-Violin's sublimation (Contradanza)