Jump to content

_SendMessage to mIRC?


 Share

Recommended Posts

Can someone give me an example of _SendMessage usage? Specifically, I'm trying to set up a script that will send commands to mIRC, but I don't have much either luck, knowledge or experience with actual programming to make it work yet. So if, for example, I wanted to send "/say Test" into mIRC, what would the code go?

{mIRC's own help page on the matter, but it's a little out of my depth for now}

Applications can now use SendMessage() to communicate with mIRC.

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

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 - create a uniquely named mapped file, where lParam = N, the mapped filename is mIRCN.

If lParam is zero, the filename is mIRC, as in previous versions.

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 - create a uniquely named mapped file, where lParam = N, the mapped filename is mIRCN.

If lParam is zero, the filename is mIRC, as in previous versions.

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 1024 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.

Link to comment
Share on other sites

Quinch,

This is actually pretty straight forward (from the IMIRC doc in the spoiler...don't have the irc client installed so cannot test, however, if you look at the doc for _sendmessage and find other examples in the forums you may be able to figure it out.

The doc in the spoiler is referring to the Windows "sendmessage" api and this is doc'ed at MSDN. The autoit _sendmessage function is a wrapper for this api...

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Well, I'm poking about DLLcall and the _SendMessage include {what's the proper term for it, while we're at it?} and since it seems pretty straightforward, I'm thinking that maybe I can skip the middleman and use DLLcall directly.

That said, and picking apart _SendMessage, I came up with;

;DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )

DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", (WinGetHandle("mIRC")), 1, "msg Test",

And this is where it breaks down. DLL, return type, Function and first type/param I lifted directly from _Sendmessage, second one is the method and sent command. So how and where do I plug in the "WM_USER + 200" bit and, for that matter, how does file mapping play into the whole thing?

Link to comment
Share on other sites

Actually, my code is incomplete and now I think it's a good idea to look for help on writing code that would work so that, with a lot of luck and someone moderately helpful, I might also understand how and why it works.

So far I'm zero for two.

Edited by Quinch
Link to comment
Share on other sites

You're not exactly helpful yourself here either. kylomas suggested the usage of _SendMessage. With the supplied documentation you posted in the original post. How far did you actually get?

I, like everyone else on this forum, don't have mIRC installed. This is probably why no one is helping you. But let me try to the most obvious thing. How about this..

Probably won't work first try, will throw errors, may not be best approach, etc. It's something to work with? If alone for the rest of the thread. Keep in mind: If you're asking a question, words don't mean anything, code does.

#Include <sendmessage.au3> ; Defines _SendMessage
#include <windowsconstants.au3> ; Defines WM_USER
#Include <winapi.au3> ; Defines $INVALID_HANDLE_VALUE
#include <memory.au3> ; Defines $PAGE_READWRITE

; mHwnd - the handle of the main mIRC window, or the handle of a Channel, Query, etc. window.
$hWnd = WinGetHandle("mIRC")

 ; WM_MCOMMAND - which should be defined as WM_USER + 200
Global Const $WM_MCOMMAND = $WM_USER + 200

; CreateFileMapping parameters from:
; http://www.experts-exchange.com/Programming/Languages/.NET/Q_21303984.html
; Parameters should be INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, "mIRC"

Local Const $size = 4096

$file = CreateFileMapping($INVALID_HANDLE_VALUE, 0, $PAGE_READWRITE, 0, $size, "mIRC")

$str = DllStructCreate("BYTE[" & $size & "]")
$ptr = DllStructGetPtr($str)
DllStructSetData($str, 1, "R0xx0r ur b0xx0r.")

WriteFile($file, $ptr, $size)

_SendMessage($hWnd, $WM_MCOMMAND, 1, 0)

CloseHandle($file)



; From: http://www.autoitscript.com/forum/topic/110111-mem-insert/page__view__findpost__p__773686 & a bit modified
Func CreateFileMapping($hFile, $lpAttributes, $flProtect, $dwMaximumSizeHigh, $dwMaximumSizeLow, $lpName)
    $HANDLE = DllCall("Kernel32.dll","HANDLE","CreateFileMappingW","HANDLE",$hFile,"PTR",$lpAttributes,"DWORD",$flProtect,"DWORD", _
    $dwMaximumSizeHigh,"DWORD",$dwMaximumSizeLow,"STR",$lpName)
    if Not @error Then Return $HANDLE[0]
    Return 0
EndFunc

; From: http://www.autoitscript.com/forum/topic/110111-mem-insert/page__view__findpost__p__773686
Func WriteFile($hFile,$lpBuffer,$nNumberOfBytesToWrite,$lpOverlapped = 0)
    $BOOL = DllCall("Kernel32.dll","INT","WriteFile","HANDLE",$hFile,"PTR",$lpBuffer, _
    "DWORD",$nNumberOfBytesToWrite,"LONG*",0,"PTR",$lpOverlapped)
    if Not @error Then Return $BOOL[0]
    Return 0
EndFunc

; From: http://www.autoitscript.com/forum/topic/110111-mem-insert/page__view__findpost__p__773686
Func CloseHandle($hObject)
    $BOOL = DllCall("Kernel32.dll","INT","CloseHandle","HANDLE",$hObject)
    if Not @error Then Return $BOOL[0]
    Return 0
EndFunc


#cs  ===========================
     /     I GOT DAT
    |   GOOGLE FU, BITCHES!      LOLOL MOAR
        ___ /               ____/
      _/ oo               /  OO
     |(   u/__    _XXX____/    O/
           __)  /            /
       /        |  _____    /
      /      _ /  /       
     `"""""``   ""        ""
#ce  ===========================

Btw,in help file, search: _WinAPI_WriteFile, _WinAPI_CloseHandle. This is work for you.

Edited by Manadar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...