Appliction instances synchronization

I wanna know how to synchronize some instances of my application. Imagine that apllication reads ini-file, prepare GUI controls and waits for user action. Second/third application instance can edit ini-file so first instance can interprets ini-file in non correct way. So the question is how to send notification from one instance and how to recieve that message in another instances.
Who is Participating?
mflamConnect With a Mentor Commented:
What you want is communication between processes. ("communication over Process boundaries").

This can be done in several ways:
1. win32 messages:
You define a message
#define WM_MYMESS WM_USER + 1

Then you SendMessage(...) it, with an instance number. (Either the windows instance or some instance number you supply.)

And in the messageloop you add a

2. Use Pipes.
a. This is similar to opening a shared file, except that whoever opens pipe get's immediate notification that file changed.
You will write into the pipe (file) a number (0 = no-one changed anything, 1 = instance 1 changed, 2 = etc.)
b. Or use named pipes:
Have a pipe for each instance open (not trivial) with instance number in name.

3. Use winsock.
Make a server (external to your instances, or in a thread of the first instance) and the others write to the server with a number and are notified by the server.

As you see, the easiest and fastest is win32 messages, except for a few drawbacks.
 Enjoy,  Moshe
I think, best way is using Syncronization metod Mutex
with Api CreateMutex,OpenMutex,
ReleaseMutex. I use this metod
for test existance of same instance,
you can test open some file:
say CreateMutex(and test by opened) befor open , and ReleaseMutex after close.
I hope, it helps. Alex.
BTWE: If you want i can send you my code (tomorrow).

AVaulinAuthor Commented:
I'll wait for tomorrow. But I'm know all (or almost all) about Mutex functions. I want to notify and recieve notification at run-time. Read question more carefull. Waiting for tomorrow (or for your code)...
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

>>I'm know all (or almost all) about Mutex
so , you don't need my code, but:

  HANDLE hMutex = CreateMutex(NULL,TRUE, "wkadip_mutex");
  if (hMutex)//real one? MUTEX_ALL_ACCESS
      if (GetLastError() != ERROR_ALREADY_EXISTS)
2. For  
>>can interprets ini-file in non correct way
You can simple use LockFile Api!
AVaulinAuthor Commented:
Sorry, I can't accept this answer. I don't want lock file. I want to know if one instance changed it. Other words: imagine dialog-based application with only one check-box control. You can run more than one instances. Check-box state changing in one instance must chagne state in all another. How can I do that?
When receiving the WM_COMMAND with BN_CLICKED notification for the first control , send the second window a message ( or Set an event that will release a thread waiting ) to change the check box .
AVaulinAuthor Commented:
This is not an answer I waited for. But it gave me a start point to find answer by meself.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.