473,387 Members | 1,516 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.

Return string using SendMessage from native code

Hi all,

In C# system service I need to get some string from MFC mainframe
window by SendMessage() API call. I managed to send message, but can
not find the way to return string to C# app.
Is that possible to receive string back in C# from return value, wparam
or lparam?

Please if someone did it post the example,

I would greatly appreciate,
Roman

Nov 17 '05 #1
10 5722
Roman,

Yes, it is. You can declare the parameter (lParam or wParam) as a
StringBuilder instance (since I assume that the MFC code is only writing to
memory that is already allocated. If it is not, then shame on it) when
declaring the SendMessage API.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mu******@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

In C# system service I need to get some string from MFC mainframe
window by SendMessage() API call. I managed to send message, but can
not find the way to return string to C# app.
Is that possible to receive string back in C# from return value, wparam
or lparam?

Please if someone did it post the example,

I would greatly appreciate,
Roman

Nov 17 '05 #2
Thanks, for quick response,
actually I did it like this:
C# side
StringBuilder sb = new StringBuilder(256);
SendMessage(process.MainWindowHandle, WM_GET_AUTH_MEMBER, 0, sb);

C++ side
CString member = "SomeString";
strcpy((char*)lParam, member.GetBuffer());

Then on C# side sb has not been changed
Any idea ?
Thanks

Nov 17 '05 #3
What is your declaration of SendMessage?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mu******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks, for quick response,
actually I did it like this:
C# side
StringBuilder sb = new StringBuilder(256);
SendMessage(process.MainWindowHandle, WM_GET_AUTH_MEMBER, 0, sb);

C++ side
CString member = "SomeString";
strcpy((char*)lParam, member.GetBuffer());

Then on C# side sb has not been changed
Any idea ?
Thanks

Nov 17 '05 #4
It is
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int
wParam, StringBuilder lparam);

Nov 17 '05 #5
I forgot to tell that the window I am sending the message is in
different process.
Probably I need to lock that memory in StringBuilder buffer to prevent
it from being destroyed
between processes
Thanks

Nov 17 '05 #6
What you are trying to accomplish is not possible using SendMessage.
SendMessage can only be used to pass a message to a Window, the receiving
Window procedure gets a copy of the message, but it cannot change or return
to the original message buffer.

Willy.
<mu******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks, for quick response,
actually I did it like this:
C# side
StringBuilder sb = new StringBuilder(256);
SendMessage(process.MainWindowHandle, WM_GET_AUTH_MEMBER, 0, sb);

C++ side
CString member = "SomeString";
strcpy((char*)lParam, member.GetBuffer());

Then on C# side sb has not been changed
Any idea ?
Thanks

Nov 17 '05 #7
If it is in another process, then I don't think this will work. The
reason for this is that in the other process, the address that you pass in
isn't valid in that context (since virtual address spaces are local to the
process).

You won't be able to get that string across the process boundary through
SendMessage.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mu******@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I forgot to tell that the window I am sending the message is in
different process.
Probably I need to lock that memory in StringBuilder buffer to prevent
it from being destroyed
between processes
Thanks

Nov 17 '05 #8
Thanks all of you,

can you suggest if there is any way to get information from the process
when I created instance of Process object in C# system service using
just process ID? I need to get some string from MainFrame member
variable.

Thank you in advance
Roman

Nov 17 '05 #9
I forgot to tell that the window I am sending the message is in
different process.
Probably I need to lock that memory somehow from being destroyed.
Thanks

Nov 17 '05 #10
If you need to transfer messages back and forth between processes you'll
need to set-up some form of IPC. One way to accomplish this is using .NET
Remoting this requires both processes to be .NET based, which as far as I
understood is not the case.
There are other forms of IPC possible, but in this case I would simply use a
file and write the string to it so that the other process can read it back.

Willy.

<mu******@hotmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Thanks all of you,

can you suggest if there is any way to get information from the process
when I created instance of Process object in C# system service using
just process ID? I need to get some string from MainFrame member
variable.

Thank you in advance
Roman

Nov 17 '05 #11

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

Similar topics

0
by: Juan Carlos CORUÑA | last post by:
Hello all, I have developed an automation server using Mark's win32 extensions and I must return a IStream COM object from one method of the automation server. Here is an extract of my code:...
5
by: Adam Clauss | last post by:
I am attempting to set the text on a richedit control in another application using EM_SETTEXTEX:...
3
by: Steve Barnett | last post by:
I have an app that includes two side by side Rich Text controls. What I need to do is keep both controls synchronised, such that if I scroll the left rtb up or down then the right one scrolls by...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
4
by: LamNgo | last post by:
Hi group, I have two application that need to communicate with each other, one written in C++ and the other in VB.NET. To communicate, I use "SendMessage" API to send message from C++ app to...
2
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);
2
by: =?Utf-8?B?QWxleCBLLg==?= | last post by:
Hi all My TreeView has unicode and english labels. The treeview shows OK on the screen. When I am trying to get an item's label using TVM_GETITEM API message, the buffer returned by SendMessage...
14
by: Kerem Gümrükcü | last post by:
Hi, i want to emulate a (synchronous) BroadCastSystemMessage with EnumWindows and SendMessage. I dont want to use the BroadcastSystemMessage because it needs the SE_TCB_NAME Privilege (you...
5
by: AliR \(VC++ MVP\) | last post by:
Hi everyone, I need to draw some rft to the screen. And I found some code out there that uses a Richedit control and sends it an EM_FORMATRANGE to do exactly that. Now I need to add scaling to...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.