aac
asked on
Synchronization between applications
I have a DLL which is being used by 2 applications. I want to synchronize the accesing of the DLL using a mutex. I
I used a CMutex object and used CSingleLock to lock and unlock the resource(DLL). It is working in the same apllication. But across applications the DLL is not getting locked. I want to know what is the reason and solution for this. Kindly help me. Is it not possible thro mutexes? Can I know that process of putting the applications in OLE out-of-process server and Yonat suggested to me?
Chensu: I have given the object name for the mutex.
The code construct is as follows:
CMutex mutObj; //in global scope
//inside my resource
CSingleLock singleLock(&mutObj);
singleLock.Lock();
{
;;;;
}
singleLock.Unlock();
The exclusion is taking place within the appln but not across the applns.
I used a CMutex object and used CSingleLock to lock and unlock the resource(DLL). It is working in the same apllication. But across applications the DLL is not getting locked. I want to know what is the reason and solution for this. Kindly help me. Is it not possible thro mutexes? Can I know that process of putting the applications in OLE out-of-process server and Yonat suggested to me?
Chensu: I have given the object name for the mutex.
The code construct is as follows:
CMutex mutObj; //in global scope
//inside my resource
CSingleLock singleLock(&mutObj);
singleLock.Lock();
{
;;;;
}
singleLock.Unlock();
The exclusion is taking place within the appln but not across the applns.
ASKER
Edited text of question
ASKER
Edited text of question
I think the CMutex object can be used across process boundaries. But you must specify the name of the CMutex object. Do you specify a name when you construct the object?
ASKER
Edited text of question
No, you haven't given a name for the mutex. It is not the C++ object name. Use the following code.
CMutex mutObj(FALSE, _T("MyMutex"));
mutObj will reference the mutex "MyMutex". If you don't give it a name, it will create a new mutex, in which case you have two seperated mutex objects created in two processes.
CMutex mutObj(FALSE, _T("MyMutex"));
mutObj will reference the mutex "MyMutex". If you don't give it a name, it will create a new mutex, in which case you have two seperated mutex objects created in two processes.
ASKER
Chensu's answer worked out!!! Hats off to Chensu. Thank U very much for prompt answers.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To have the same objects shared by to processes (applications), you will need to put them in an OLE out-of-process server.