brian
brian

Reputation: 217

Send windows messages with Mono

Is it possible to send windows messages (WM_...) to other applications using Mono (assuming that my app is running on Windows)? Another related question is whether there is any way to use DDE inside a Mono app?

Thanks!

Upvotes: 1

Views: 1310

Answers (2)

jpobst
jpobst

Reputation: 9982

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.

Upvotes: 2

VMykyt
VMykyt

Reputation: 1629

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

Upvotes: 2

Related Questions