Talking about the application example problem Guangzhou Zhiushi Lu Bin - "Visual C Programming Skise", "Visual C Programming" provides a solution to the application can only run an instance, I found the effect after practical Yes, but also found that if you make a modification of the name of the application execution, the modified file can still start multiple instances. And UltraEdit, Gtright and other software do not exist. ---- After viewing the help of the code and VC, the found problem is that the original text is used when creating a semaphore and settings to find a tag, a member variable m_pszezeename of CWINAPP. The member variable is actually the name of the application execution file to remove the extension, not the application name. The real application name should be a member variable m_pszappname. Three code will be changed to m_pszappname to M_PSZAPPNAME, and the case disappears. ---- Although the user does not modify the name of the application executive file, as a developer, our responsibility is to be perfect as possible, there is a defect, therefore, thus write this short message to make supplements. ---- Finally, provide a method and a message: ---- 1. Another way to make the application can only run an instance, just add the following statements in InitInstance (): Handle M_HMutex =
Createmutex (NULL, TRUE, M_PSZAPPNAME);
IF (getLastError () == Error_Already_exists) {
Return False;
}
---- But the shortcomings of this method cannot activate instances that have been started. ---- 2. Some methods are also provided in the MFC FAQ software organized by StingRay. The software is actually a large collection of MFC usage skills, which is very helpful to use MFC, and friends may wish to go to Stingray's homepage (http://www.sting "or http://www.stingsoft.com).