开发者

Send windows messages with Mono

Is it possible to send windows messages (WM_...) to other applications using Mono (assuming that my app i开发者_运维问答s running on Windows)? Another related question is whether there is any way to use DDE inside a Mono app?

Thanks!


well, if I were you I would strarted from

  • mono to winapi32
  • sending win message using winapi32

So just try any "hello_world" sample. (I haven't mono right now, sorry for this)

For example you may just compile the following code:

(stolen from http://boycook.wordpress.com/2008/07/29/c-win32-messaging-with-sendmessage-and-wm_copydata/)

using System.Runtime.InteropServices;
public class MessageHelper
{

[DllImport("User32.dll")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, 
ref COPYDATASTRUCT lParam);
}

//Used for WM_COPYDATA for string messages
public struct COPYDATASTRUCT
{
   public IntPtr dwData;
   public int cbData;
   [MarshalAs(UnmanagedType.LPStr)]
   public string lpData;
}

I suppose it compiles and it doesn't thow DllNotFoundException or EntryPointNotFoundException when you call

MessageHelper.SendMessage(100, 100, new COPYDATASTRUCT());

If you have some issue with this... Hmm.. You may tray to load mscorlib.dll at the runtime. But this way have bad smell.

Also you may find some details here http://www.mono-project.com/Interop_with_Native_Libraries


Yes, you should be able to send WM_* messages to and from Mono on Windows applications exactly like any other Windows application.

Mono Winforms imitates and integrates with the regular Windows message pump when running on Windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜