Let the program run only one C + + Builder implementation at the same time

Source: Internet
Author: User

Source: Let the program run only one

Many people have discussed this problem, which is done with the existing shared memory feature in the Victor serial control. when the program runs the second time, it simply activates the first run window instead of running a program.

Need to be implemented in the main program, belowthe blue partIs the added content:

#include <vcl.h> #pragma hdrstop

#include "yb_base.h"

//---------------------------------------------------------------------------

Useform ("UnitTestMain.cpp", Form1);

//---------------------------------------------------------------------------

WINAPI WinMain (hinstance, HINSTANCE, LPSTR, int)

{

//Two programs cannot have the same flag, programs with the same flag can only run one

tsharedmemory Appmark ("victor_20030526_2131", 4096); //Use shared memory to Set program flags

if (appmark.exists) //The program is already running

{

Appmark.activeappwnd (); //Activate a program window that is already running

return 0; //Exit program

}

Appmark.clearbuffer (); //Clear Cache

Try

{

Application->initialize ();

Application->createform (__classid (TFORM1), &form1);

Appmark.appinfo->hmainwnd = application->handle; //Handle is saved in shared memory

Application->run ();

}

catch (Exception &exception)

{

//.... Omit for future content

Let the program run only one C + + Builder implementation at the same time (go)

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.