Click here to Skip to main content
15,912,207 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralAvoiding duplicate Exe running simultaneously Pin
J_E_D_I5-Apr-08 3:28
J_E_D_I5-Apr-08 3:28 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
rp_suman5-Apr-08 4:13
rp_suman5-Apr-08 4:13 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
J_E_D_I5-Apr-08 4:42
J_E_D_I5-Apr-08 4:42 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
J_E_D_I5-Apr-08 21:25
J_E_D_I5-Apr-08 21:25 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
Jim Crafton5-Apr-08 4:48
Jim Crafton5-Apr-08 4:48 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
J_E_D_I5-Apr-08 21:33
J_E_D_I5-Apr-08 21:33 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
Jim Crafton6-Apr-08 4:39
Jim Crafton6-Apr-08 4:39 
GeneralRe: Avoiding duplicate Exe running simultaneously Pin
Gary R. Wheeler6-Apr-08 1:43
Gary R. Wheeler6-Apr-08 1:43 
Here's my solution:
/* MultipleInstance.h */
 
class MultipleInstance {
 
public:
 
    MultipleInstance();
    ~MultipleInstance();
 
    static bool Active();
 
private:
 
    static bool                 _Active;
 
    static bool                 _Initialized;
    static HANDLE               _Handle;
    static MultipleInstance     *_Instance;
 
};
 
/* MultipleInstance.cpp */
 
static MultipleInstance _MultipleInstance;
 
bool                MultipleInstance::_Active       = false;
 
bool                MultipleInstance::_Initialized  = false;
HANDLE              MultipleInstance::_Handle       = NULL;
MultipleInstance    *MultipleInstance::_Instance    = &_MultipleInstance;
 
MultipleInstance::MultipleInstance()
{
    if ((!_Initialized) && (this == _Instance)) {
 
        // create security descriptor to let all users access the semaphore
 
        SECURITY_DESCRIPTOR security_descriptor = { 0 };
 
        InitializeSecurityDescriptor(&security_descriptor,
                                     SECURITY_DESCRIPTOR_REVISION);
 
        SetSecurityDescriptorDacl(&security_descriptor,TRUE,NULL,FALSE);
 
        // create semaphore
 
        SECURITY_ATTRIBUTES security_attributes = { 0 };
 
        security_attributes.nLength              = sizeof(security_attributes);
        security_attributes.lpSecurityDescriptor = &security_descriptor;
        security_attributes.bInheritHandle       = FALSE;
 
        SetLastError(0);
 
        _Handle = ::CreateSemaphore(&security_attributes,0,1,
                                    _T("Global\\InstanceSemaphore"));
                                    /* change "InstanceSemaphore" to your desired name */
 
        if (GetLastError() == ERROR_ALREADY_EXISTS) {
            _Active = true;
        }
 
        _Initialized = true;
 
    }
}
 
MultipleInstance::~MultipleInstance()
{
    if (_Initialized && (this == _Instance)) {
 
        if (_Handle != INVALID_HANDLE_VALUE) &&
           (_Handle != NULL)) {
 
            CloseHandle(_Handle);
            _Handle = NULL;
 
        }
 
    }
}
 
bool MultipleInstance::Active()
{
    return _Active;
}


Software Zen: delete this;
Fold With Us![^]

GeneralRe: Avoiding duplicate Exe running simultaneously Pin
J_E_D_I6-Apr-08 19:55
J_E_D_I6-Apr-08 19:55 
GeneralGet how much bytes transferred CFTPConnetion and PutFile() Pin
chetanjoshi95-Apr-08 1:49
chetanjoshi95-Apr-08 1:49 
Questionseting a blank date as the initial value for Date Time Picker control Pin
Priya_Sundar4-Apr-08 22:51
Priya_Sundar4-Apr-08 22:51 
GeneralRe: seting a blank date as the initial value for Date Time Picker control Pin
rp_suman5-Apr-08 4:30
rp_suman5-Apr-08 4:30 
GeneralRe: seting a blank date as the initial value for Date Time Picker control Pin
Priya_Sundar8-Apr-08 21:59
Priya_Sundar8-Apr-08 21:59 
QuestionRe: seting a blank date as the initial value for Date Time Picker control Pin
rp_suman11-Apr-08 3:46
rp_suman11-Apr-08 3:46 
Questionmarshall interface needed? Pin
George_George4-Apr-08 21:33
George_George4-Apr-08 21:33 
AnswerRe: marshall interface needed? Pin
Eytukan5-Apr-08 7:57
Eytukan5-Apr-08 7:57 
GeneralRe: marshall interface needed? Pin
Maximilien5-Apr-08 14:33
Maximilien5-Apr-08 14:33 
GeneralRe: marshall interface needed? Pin
George_George6-Apr-08 15:45
George_George6-Apr-08 15:45 
GeneralRe: marshall interface needed? Pin
George_George6-Apr-08 15:44
George_George6-Apr-08 15:44 
Generalasynchronous and synchronous call between apartments Pin
George_George4-Apr-08 21:24
George_George4-Apr-08 21:24 
QuestionHow can Fix Window size as Maximize? Pin
Le@rner4-Apr-08 18:34
Le@rner4-Apr-08 18:34 
AnswerRe: How can Fix Window size as Maximize? Pin
rp_suman4-Apr-08 21:57
rp_suman4-Apr-08 21:57 
GeneralRe: How can Fix Window size as Maximize? Pin
Le@rner4-Apr-08 22:29
Le@rner4-Apr-08 22:29 
GeneralRe: How can Fix Window size as Maximize? Pin
Le@rner4-Apr-08 23:14
Le@rner4-Apr-08 23:14 
QuestionRe: How can Fix Window size as Maximize? [modified] Pin
rp_suman4-Apr-08 23:42
rp_suman4-Apr-08 23:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.