Link to home
Start Free TrialLog in
Avatar of aac
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.

Avatar of yonat
yonat

I think that each application loads a seperate instance of the DLL into it's own process space.

To have the same objects shared by to processes (applications), you will need to put them in an OLE out-of-process server.
Avatar of aac

ASKER

Edited text of question
Avatar of aac

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?
Avatar of aac

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.
Avatar of aac

ASKER

Chensu's answer worked out!!! Hats off to Chensu. Thank U very much for prompt answers.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial