Home > Software engineering >  How to control an application can only single drive can't open
How to control an application can only single drive can't open

Time:10-19

As title, I want to use tecplot. Exe opened several respectively. MCR file, use the shell command:
Shell tecplot. Exe macro1. "MCR"
Shell tecplot. Exe macro2. "MCR"
Shell tecplot. Exe macro3. "MCR"
Command can open, but will jump out to three tecplot. Exe interface window, how to make the back of the macro2. MCR and macro3. MCR in open when using the first tecplot window interface, which is always only one tecplot window rather than more? Should from which aspects to solve the problem, using MFC can

CodePudding user response:

Similar to use Windows video player can only open a video that

CodePudding user response:

Under Windows can use named mutex to solve only run one instance
http://blog.163.com/hack_0xspy/blog/static/1984280252011101141319245/

CodePudding user response:

With a global mutex, each time you start, create the mutex, to see if the error information returned that already exists, if it exists, the current process exits

CodePudding user response:

To create the named kernel object

CodePudding user response:

When start to create a named kernel object, and then determine whether the kernel object is created successfully, if is to create failure, then it will already have an instance startup

CodePudding user response:

 HANDLE hMutex=CreateMutexW (NULL, TRUE, L "mutex"); 
If (hMutex!=NULL)
{
If (GetLastError ()==ERROR_ALREADY_EXISTS)//process mutex
{
Return FALSE;
}
}

At the time of initialization program and code

CodePudding user response:

//the Variables Shared across indicates all instances of our application which ensure
//that only one instance of this application will run at a given time.
The # pragma data_seg (" Shared ")
The static LONG g_lInstanceCount=1;
# pragma data_seg ()

# pragma data_seg (" drectve ")
The static char szShared []="- section: Shared, RWS";
# pragma data_seg ()

//////////////////////////////////////////////////////////////////////////////////

If (InterlockedIncrement (& amp; G_lInstanceCount) & gt; 0)
{
InterlockedDecrement (& amp; G_lInstanceCount);
MessageBox (NULL, __TEXT (" the Display Resolution is already running "),
G_szAppName, MB_ICONINFORMATION | MB_OK);
}
  • Related