Windows core programming code analysis based on Visual C ++

Source: Internet
Author: User

As you can see, Thunder can only start one task. How can this be implemented in the middle of the code? Let's practice it in the code.

[CPP]View
Plaincopyprint?

  1. # Include <windows. h>
  2. # Include <stdio. h>
  3. Int main (INT argc, char * argv [])
  4. {
  5. Handle hmutex;
  6. DWORD dwerr;
  7. Hmutex = createmutex (null, // No security description
  8. False, // No owner
  9. "Hack"); // Object Name
  10. If (hmutex = NULL) // If hmutex is null, the creation fails.
  11. {
  12. MessageBox (null, "createmutex error! ", Null, mb_ OK );
  13. }
  14. Else
  15. {
  16. Dwerr = getlasterror ();
  17. If (dwerr = error_already_exists) // The mutex object already exists.
  18. {
  19. MessageBox (null, "application has already running", null, mb_ OK );
  20. Exitprocess (0 );
  21. }
  22. }
  23. Getchar ();
  24. Return 0;
  25. }

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.