RE: Send Message(string) c# exe to vc++ exe(unmanaged) using WindowsS

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



My demo project showing how to only run one copy of a program also
demonstrates how to send a message, using C#, to another program using the
SendMessage WIN32 API method.

http://www.dalepreston.com/Blog/2005/03/you-only-run-once.html

HTH

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA


"Mayur" wrote:

I tried followinf but working fine fo int but how to do it for string using
user custome message

in c#
[DllImport("User32.dll")]

public static extern int FindWindow(string strClassName,string
strWindowName);

[DllImport("User32.dll")]

public static extern Int32 SendMessage(

int hWnd, // handle to destination window

int Msg, // message

int wParam, // first message parameter

[MarshalAs(UnmanagedType.LPStr)] string lParam);



public const int WM_APP = 0x8000;

public const int WM_DELETEALL =WM_APP + 0x100;

int wnd=FindWindow(null,"TestMfcSendMsgExe");

Form1.SendMessage(wnd,WM_DELETEALL,0,55);





and MFC Exe is like this

#define WM_DELETEALL WM_APP + 0x100

BEGIN_MESSAGE_MAP(CTestMfcSendMsgExeDlg, CDialog)

ON_MESSAGE (WM_DELETEALL, OnDeleteAll)


END_MESSAGE_MAP()

LRESULT CTestMfcSendMsgExeDlg::OnDeleteAll(WPARAM wParam, LPARAM lParam)

{

MessageBox("Hello","Mayur",MB_OK);

}

I am getting the message box after using SendMessage() in c# exe but i want
to send text(string ) information.

I need help..

Regards,

Mayur.





.



Relevant Pages

  • Re: Send Message(string) c# exe to vc++ exe(unmanaged) using WindowsSendMessage
    ... public static extern int FindWindow(string strClassName,string ... LRESULT CTestMfcSendMsgExeDlg::OnDeleteAll(WPARAM wParam, LPARAM lParam) ... public static extern IntPtr SendMessage; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Object reference error on EnumChildWindows
    ... int lParam); ... public static extern int EnumWindows ... public static extern void GetWindowText(int h, StringBuilder s, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Object reference error in EnumChildWindows
    ... int lParam); ... public static extern int EnumWindows ... public static extern void GetWindowText(int h, StringBuilder s, int ... public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int ...
    (microsoft.public.dotnet.framework.interop)
  • Object reference error on EnumChildWindows
    ... int lParam); ... public static extern int EnumWindows ... public static extern void GetWindowText(int h, StringBuilder s, int ... public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to send a message ??
    ... > You need a prototype for SendMessage: ... > public static extern int SendMessage(IntPtr hwnd, int wMsg, int ...
    (microsoft.public.dotnet.framework.windowsforms)