sendmessage and mapped files

TheDon

Member
Joined
Nov 3, 2003
Messages
5
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?
 
Anyone know about this?

I am also curious about this, and this is the only post about mapping files that comes up when searched.

Does anyone have any experiance on mapping files to do the functions found here?
 
Heres a function to run any command via sendmessage, ripped it from a neat little dll virus source.

mWnd would be the handle to the mIRC window

in C/C++ code:

Code:
void SendCommand(HWND mWnd, char *command)
{
	HANDLE hMapFile;
	LPSTR mData;

	hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, "mIRC");
	mData = (LPSTR)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
	wsprintf(mData, command);
	SendMessage(mWnd, WM_MCOMMAND, 1, NULL);
	UnmapViewOfFile(mData);
	CloseHandle(hMapFile);
}
 
Back
Top