0

I pretty much like the way a window is send/received messages and I want to reuse that for process inter-communications - I've heard of named pipes but I don't want to write to a file - it seems ugly and unintuitive for me.

So is it possible to create a window with sharable handle across multiple processes?

AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
  • I'm not a Windows programmer, but this seems like a pretty high-overhead mechanism. – Barmar Apr 19 '19 at 17:43
  • This is also not really an appropriate question for [so]. You need to ask specific questions about code, we don't really engage in general design discussion. – Barmar Apr 19 '19 at 17:45
  • @Barmar I'm asking a specific question - what are you talking about? – AnArrayOfFunctions Apr 19 '19 at 17:47
  • Where is the code you're asking the specific question about? – Barmar Apr 19 '19 at 17:48
  • @Barmar First time I hear that code is required to ask a specific question. I think I may use mailslots. – AnArrayOfFunctions Apr 19 '19 at 17:49
  • Good questions should be something that can have an objectively correct answer. This question is looking for design advice, which is likely to be opinionated, not objective. – Barmar Apr 19 '19 at 17:53
  • Well the question ask how to create a global windows - is it possible? – AnArrayOfFunctions Apr 19 '19 at 17:57
  • A window handle is shareable by default, but owned by a specific process. Using window messages for IPC is a lightweight mechanism that can work well for simple scenarios. Search for `WM_COPYDATA`. – zett42 Apr 19 '19 at 18:21
  • 1
    Possible duplicate of [Use WM\_COPYDATA to send data between processes](https://stackoverflow.com/questions/2451103/use-wm-copydata-to-send-data-between-processes) – zett42 Apr 19 '19 at 18:28
  • 1
    @bar: It's not as high-overhead as you might think. The system even encourages this by providing the ability to create [message-only windows](https://learn.microsoft.com/en-us/windows/desktop/winmsg/window-features#message-only-windows) precisely for that purpose. – IInspectable Apr 20 '19 at 15:24
  • "*I've heard of named pipes but I don't want to write to a file*" - Named pipes have nothing to do with files, though I/O through a named pipe can be done using some of the same APIs as file I/O. – Remy Lebeau Apr 21 '19 at 06:25
  • @RemyLebeau Named pipes are a special file in unix, as well as in windows. But it's not in a normal file system in Windows, every pipe is placed in the root directory of the named pipe filesystem(NPFS), mounted under the special path \\.\pipe\ – Drake Wu Apr 22 '19 at 07:59

1 Answers1

0

Window handles are shared by default, just as you can find them through FindWindow or FindWindowEx. What you want is a bit like socket communication, client-server-client transit protocol. It's just that sockets are more powerful and can be used on different machines.

You can communicate between processes by defining your own WM_* message type, and you can control "multi-to-multi" inter-process communication. But it is not practical in practice (if ugliness is not taken into account), it is not as powerful as socket, not as mature as socket's technology, more resource occupied(because of visible window).

Of course, as @IInspectable said, there is another way of message-only windows. But the window is not visible, which is not "intuitive". Getting a window handle is as "ugly" as opening a file. It's like encapsulating a message queue into an invisible window. In addition, if the window is accidentally closed, the communication will fail.

So summary: You can use the visible window to communicate between processes according to your preferences, but this method is not practical (unless there is a special need).

Drake Wu
  • 6,927
  • 1
  • 7
  • 30