SendMessage

 

mIRC supports SendMessage communication, which allows external applications to control mIRC or to request information from it. Note that it is also possible to communicate with mIRC by using DDE.

 

Performing Commands

The following call to SendMessage() makes mIRC perform the commands that you specify:

 

  SendMessage(mHwnd, WM_MCOMMAND, cMethod, cIndex)

 

  mHwnd - the handle of the main mIRC window, or the handle of a Channel, Query, etc. window.

 

  WM_MCOMMAND - which should be defined as WM_USER + 200

 

  cMethod - how mIRC should process the message, where:

          1 = as if typed in editbox (default)

          2 = as if typed in editbox, send as plain text

          4 = use flood protection if turned on, can be or'd with 1 or 2

          8 = use unicode text

 

  cIndex - use a named mapped file, where lParam = N, the mapped filename is mIRCN.

               If lParam is zero, the filename is mIRC.

 

  Returns - 1 if success, 0 if fail

 

Evaluating Identifiers and Variables

The following call to SendMessage() makes mIRC evaluate the contents of any line that you specify:

 

  SendMessage(mHwnd, WM_MEVALUATE, cMethod, cIndex)

 

  mHwnd - the handle of the main mIRC window, or the handle of a Channel, Query, etc. window.

 

  WM_MEVALUATE - should be defined as WM_USER + 201

 

  cMethod - how mIRC should process the message, where:

          8 = use unicode text

 

  cIndex - use a named mapped file, where lParam = N, the mapped filename is mIRCN.

               If lParam is zero, the filename is mIRC.

 

  Returns - 1 if success, 0 if fail

 

Mapped Files

The application that sends these messages must create a mapped file named mIRC with CreateFileMapping().

 

The lParam (cIndex) parameter indicates the mapped file name that you have used, where lParam = N, the mapped filename is mIRCN. If lParam is zero, the filename is mIRC.

 

When mIRC receives the above messages, it will open this file and use the data that this mapped file contains to perform the command or evaluation. In the case of an evaluation, mIRC will output the results to the mapped file.

 

The mapped file must be at least 4096 bytes in length.

 

To prevent simultaneous access to the mapped file, your code must check whether the mapped file exists or not before using it. If it exists, you should assume that it is in use by another program, and should try again later.

 

Remote Event Context

If during a remote event, such as on TEXT, your script calls a DLL which then uses SendMessage() to execute a command or evaluate an identifier, you can tell SendMessage() to execute in the context of that remote event.

 

During a remote event, a $eventid identifier is set to a unique value to identify the event. This can be passed to a DLL which can then pass it back to mIRC using:

 

  SendMessage(mHwnd, WM_MCOMMAND, MAKEWPARAM(cMethod, cEventId), cIndex)

 

This will cause the command/evaluation to execute in the context of the remote event identified by cEventId. If cEventId is 0, this indicates a non-remote event.

 

Extended Version Information

If cMethod is set to -1, you can set cIndex to -1 to receive the mIRC version number and to -2 to receive the cMethod options that are supported.

 

Extended Error Information

If cMethod is or'd with the value 16, SendMessage() will return more specific error values.

 

The return values are: 0 = success, 1 = failure.

 

The 1 = failure error can be or'd with 2 = bad mapfile name, 4 = bad mapfile size, 8 = bad eventid, 16 = bad server, 32 = bad script, 64 = disabled (if disabled in the Other dialog).

 

If the error is just 1, this indicates that the command/identifier returned an error.

 

The 16 and 32 errors indicate that the server/script associated with the eventid no longer exists.