WinCE program prevents multiple instances from being created _c language

Source: Internet
Author: User
Tags mutex

Process:
1. Create a mutex when the program is initialized
2, detect the exclusion of the error code returned to see if there is this mutex
3, if the same mutex already exists, then release the created mutex handle, and reset the mutex, and then exit the program

The specific code is as follows:

Copy Code code as follows:

Create mutexes
HANDLE M_hmutex = CreateMutex (NULL, FALSE, _t ("D3gphonedlg"));
Check for error codes
if (GetLastError () = = error_already_exists) {
Disposes the handle and resets the mutex if there is an existing mutex
CloseHandle (M_hmutex);
M_hmutex = NULL;
::P Ostmessagew (Hwnd_broadcast, Wm_d3gphonedlg_msg, 1, 2);//Notify Open program, activate window
Program exit
Cdialog::oncancel ();
}
"EOF" Prevents a program from creating multiple instances * *

This code is tested in the WinCE MFC program and placed in the OnInitDialog () function of the program.

When you are testing, you can start by commenting out the words that activate the window.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.