Author Topic: Non-DDE IPC?  (Read 21040 times)

DJMaze

  • Guest
Re: Non-DDE IPC?
« Reply #30 on: April 23, 2006, 01:13:42 am »
Ehm i was wondering why use shared memory when the message handler failed?

It is pretty easy to create a message queue with mutexes.
Code
int main(int argc, char** argv)
{
HANDLE Mutex = CreateMutex(NULL, false, _T("CodeBlocks"));
if (GetLastError() != 0) {
HWND hwndCB = 0;
while (!hwndCB) {
hwndCB = FindWindowEx(NULL, NULL, _T("CodeBlocks"), _T("CodeBlocks"));
}
// now send the commands to the handler
SendMessage();
return 0;
} else {
CreateWindow("CodeBlocks","CodeBlocks",....);
}
// now all CB stuff
CloseHandle(Mutex);
}

The "CodeBlocks" window is invisible and receives the messages and puts each command inside a list for processing.

Shared memory in combination with a queue is also fine. For example your 64k shared memory block will be a list of strings.
char **cmd;

The first *cmd will contain the argc so that each consecutive call will add data to the end. (don't forget to lock the memory while editing it)
After that send a message to trigger the handler.

The handler will then shift the elements off the beginning of the array in combination with memmove()

TheNullinator

  • Guest
Re: Non-DDE IPC?
« Reply #31 on: May 16, 2006, 06:14:38 am »
Hi,

Sorry for disappearing for a month and a bit.  I had a few health issues.

I rewrote most of the code this morning and last night and fixed a few good bugs in the process.  Here is a list of current issues I know about with the new code.

  • Sometimes the active window is not registered correctly as the current window so files are opened in the previously active window.
  • The window is never brought to the foreground after a file has been opened under Windows ME -- but the taskbar button flashes.
  • Sometimes under Windows ME a message about the system being low on memory is displayed after during the opening of a selection of about 30 files or so.  Also happens on repeated openings of a selection of about 8 files.  System Monitor didn't report a lack of memory.  :?  This issue doesn't occur if you repeatedly open a single file at a time.

I have placed the IPC code in a new class in the files ipc.h and ipc.cpp.  It should be easy enough to modify the code to support other operating systems.

Cheers

[attachment deleted by admin]

TheNullinator

  • Guest
Re: Non-DDE IPC?
« Reply #32 on: May 16, 2006, 06:18:52 am »
@DJMaze

I had considered taking that approach earlier on, but it seemed to me, personally, a tad untidy after I'd implemented a bit of it, though that may have just been my way of going about it.  I think Thomas' idea of using shared memory is very clean and probably easier to port.

Cheers
« Last Edit: May 16, 2006, 06:21:51 am by TheNullinator »