473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Send Message(string) c# exe to vc++ exe(unmanaged) using WindowsSendMessage

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.


Nov 24 '06 #1
2 12503
"Mayur" <ma***@activelement.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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.

First you need to correct your API signatures like this:

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strClassName,string strWindowName);

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr
lParam);

When you need to send a string, you'll have to marshal the string to a native buffer and
pass it's pointer as lParam, something like this:

IntPtr hWnd = ...FindWindow(..);
string s = "Somestring";
IntPtr sNative = Marshal.StringToHGlobalAuto(s);
IntPtr result = SendMessage(hWnd,..,.., sNative);
Marshal.FreeHGlobal(sNative);
....

Willy.

Nov 24 '06 #2
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...-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.


Nov 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew Connell | last post by:
Having fits transforming an XML string using an XSL file. In the 1.1 version of the framework, I see that the XmlResolver is heavily used in the XslTransform class. However, that looks like I am...
4
by: Dan Diephouse | last post by:
I am attempting to write a DLL which wraps C# code. The issue at hand is a print driver allows you to extend it by writing a DLL. Seeing that VC++ seems to be hopelessly out of my mental reach, I...
2
by: Maziar Aflatoun | last post by:
Hi guys, I'm using Windows authentication to connect to SQL Server 2000. On my computer the connection is fine. Now if I move it to a remote server, how to I hard code my Username/Password in...
2
by: Bruno | last post by:
Hello friends I'm creating one application that will send content to another app using HTTP connection. To authenticate my connection, I need to send a string with the username and password...
3
by: minguskhan | last post by:
Does anyone know how to reverse a string using a loop?
1
by: Mayur | last post by:
I tried followinf but working fine fo int but how to do it for string using user custome message in c# public static extern int FindWindow(string strClassName,string strWindowName);
0
by: amitsaxena | last post by:
hi, I am using c#.net 2005, i am using .net port class to access the com ports but i m confused to send the message string with present com port .i want to send the message and also return the...
6
by: Volodia | last post by:
Hi, I have a problem to find information how to add unmanaged dll build in VC++ 2005 to the asp.net web site What I have tried: 1. use DllImport("MyDll.dll") to declare function in...
6
by: koutoo | last post by:
How do I delete or remove values from a list or string using the index. If a = and I want to get rid of 1 -5, how would I do that? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.