Im trying to write a program in vb.net that will allow me to send messages to mIRC, to do this I have to create a mapped file with the actions I want mIRC to carry out, and then send a sendmessage command to it to tell it to read the file and do what it says.
This is what the mIRC help file says about it :-
=========================================
The following call to SendMessage() makes mIRC perform the commands that you specify.
SendMessage(mHwnd, WM_MCOMMAND, cMethod, 0L)
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 ord with 1 or 2
Returns - 1 if success, 0 if fail
Mapped Files
The application that sends these messages must create a mapped file named mIRC with CreateFileMapping().
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.
=========================================
Now, Ive got a function to get mIRCs hwnd, and think I have created a mapped file.... now Im having problems writing to the file, and getting mIRC to carry out the commands.
mhWnd = FindWindow("mIRC", vbNullString)
hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, "mIRC")
mData = MapViewOfFile(hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)
Ive tried everything I can think of and this is my current attempt
Dim sw As StreamWriter = New StreamWriter(mData)
sw.Write(sendmessagetext)
sw.Close()
SendMessage(mhWnd, WM_MCOMMAND, 1, 0)
The only thing I can think of is maybe Im trying to write to a physical file rather than a memory mapped one? Any ideas whats going wrong and how I can sort it?
This is what the mIRC help file says about it :-
=========================================
The following call to SendMessage() makes mIRC perform the commands that you specify.
SendMessage(mHwnd, WM_MCOMMAND, cMethod, 0L)
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 ord with 1 or 2
Returns - 1 if success, 0 if fail
Mapped Files
The application that sends these messages must create a mapped file named mIRC with CreateFileMapping().
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.
=========================================
Now, Ive got a function to get mIRCs hwnd, and think I have created a mapped file.... now Im having problems writing to the file, and getting mIRC to carry out the commands.
mhWnd = FindWindow("mIRC", vbNullString)
hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, "mIRC")
mData = MapViewOfFile(hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)
Ive tried everything I can think of and this is my current attempt
Dim sw As StreamWriter = New StreamWriter(mData)
sw.Write(sendmessagetext)
sw.Close()
SendMessage(mhWnd, WM_MCOMMAND, 1, 0)
The only thing I can think of is maybe Im trying to write to a physical file rather than a memory mapped one? Any ideas whats going wrong and how I can sort it?