I'm trying to write an application that will output lines to mirc, I did this easily before with vb6 and dde, however not I'm using vb.net due to it's multitheading support, and I can't work out how to get the sendmessage function working.

I'm using findwindow to get mirc's hwnd, then mapping a file, and then trying sendmessage, but it's not having any of it, any ideas?

This is how i've tried it so far.

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)
FileOpen(1, mData, OpenMode.Output) ' Open file for output.
Print(mData, texttosend) ' Print text to file.
SendMessage(mhWnd, WM_MCOMMAND, 2, 0L)