I want to make IPC, but I cannot use blocking mechanism (SendMessage, PIPE, TCP), and I don’t wanna use Threads (more source of errors), or storing the data (files, registry for example).
Here is 2-4 softwares in every PC, and I want to synchronize the “message existance”.
What is it? I explain it.
Every app is uses same database. They are periodically read the “messages” with two queries, and see when “normal” and “alarm” message arrived – or when they are all opened and read.
But one of them are the “chosen”, protected with mutex, and it control a trayicon, and balloon hint. When message arrived, it reflected on tray.
When this app die, another trying to get the mutex, and control the tray.
I want to use the IPC to say the “master” if the state changed (new message arrived, or all messages read) to master know about this, and we avoid this situation:
Master show the tray and balloon, and user read the messages in another app. In this case the master don’t know about it, and continue to show the “new messsage” controls. Or master read all, but a new message arrived. In this time the master must inform about this.
Because the checking periods are: normal message – 5 minutes, alarm – 2 minutes.
So: why I don’t use blocking IPC, like SendMessage?
Because if the master starts a big query (5 minutes) then the another apps are blocked for these time.. 🙁
Previously I tried with temp files, registry writing, but every of them is have the problem of “cleaning”, so data remaining…
Then I have an idea the every form is visible for “EnumWindows”. If messages are stored in Title, I only do PostMessage with the Handle of this form, and the Master can read the Title, process the message.
If 15 minutes passed, we ignore this message, and the “message” window destroyed.
Ok, ok, it is don’t elegant, but I don’t know about any way that don’t store anything in files, and cannot block (async) – without threading hell.
proc Send(Info : string):
handles = EnumAndFindHandles();
for handle in handles:
o = CreateMessageForm(handle, Info);
PostMessage(WM_MYMSG, handle, 11111, integer(o.Handle));
proc Recv(var Msg):
if IsHandleValid(Msg.lParam) and ClassNameIsGood(Msg.lParam):
txt = ReadWindowText(Msg.lParam);
if txt > '':
...
I want to know two things:
1.) Do you know any situation when this communication can failed? (Caption is missing, changed or other thing that can blocking this way)?
2.) As I see only the Forms can visible in EnumWindows? Do you know a way to do this with another control?
Thanks for any ideas, good informations, suggestions!
dd
For me it sounds like memory mapped files could be a simple solution: share a block of memory between your applications, just like with a temp file. You said you considered file-based methods but don’t like the traces they leave. With memory mapped files the traces will be in the page file, which might not be such a big deal as with the registry or temporary files.