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 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
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
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
It is
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int
wParam, StringBuilder lparam);
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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:...
|
by: Adam Clauss |
last post by:
I am attempting to set the text on a richedit control in another application
using EM_SETTEXTEX:...
|
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...
|
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...
|
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...
|
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);
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
| |