The Win32 IPC transport uses Windows messages to direct the request to Snarl. In order for this to work, Snarl creates a hidden window with a known title and class name. Applications should populate a COPYDATASTRUCT data type with the request and send it to this window.
Requests are sent as Windows messages via the WM_COPYDATA message. This message allows for very simple but powerful process-to-process communication within a Windows session.
The Win32 IPC transport expects all notification content to be in UTF-8 format. Hence, the communication process is as follows:
This translates into the following pseudo-code:
COPYDATASTRUCT data type, no other changes should be made.
All Win32 IPC requests return a 32-bit integer result as a result of the call to SendMessageTimeout(). If it succeeds (result is non-zero), the status code of the request will be returned in lResult; if it fails (result is zero), the exact cause of the failure can be determined by calling GetLastError().
The returned status code is encoded as follows: a negative value indicates an error, a result of zero indicates success, and a positive value indicates success and some information was returned (for example, a notification's token). Translation into a real status code is simply a case of converting to an absolute value, as follows:
In order to receive events, the application must supply two additional pieces of information to Snarl when registering:
The handle to the window should be included in the reply-to argument; the message should be in the reply-with argument. As the message will be returned to the application, it is recommended that the message is chosen from the user message range. For example:
Subsequent events will then appear in the window's message queue as follows:
The following table explains how wParam is encoded for the different events:
Note that although Snarl supports alphanumeric identifiers, the Win32 IPC transport does not. Consequently, it must be possible to convert the identifier into a valid 16-bit integer for it to work. So, @1234, @-1 and @65535 are valid, while @HELLO, @65536 and @123$ are not.