views:

262

answers:

2

Hi All,

I have two exe's one in C# and other is a vc++ exe . Both of these exe need to access a file.

So I am planning to create a named mutex in c#. vc++ how can i access this named mutex. Can any one give me sample codes for this

A: 

If you have created the mutex in c# , Your C++ code would be something like:

HANDLE mutexHandle = OpenMutex(SYNCHRONIZE,0,"NameOfYourMutex");
if(mutexHandle == 0) {
  //handle error
}
nos
+1  A: 

Something like this in the C++ code:

HANDLE hMutex = CreateMutex(NULL, FALSE, name);
if (hMutex == NULL) {
  // Handle failure.
}

If you need to know if the mutex already existed, check for hMutex != null && GetLastError() == ERROR_ALREADY_EXISTS.

The default ACL you get should be OK for cases with both processes in the same session, otherwise you will need to set an appropriate ACL.

Richard