Sending Windows msgs: C# to C++

K

Kevin

First off, thanks to everyone in all groups for helping in the past.

I'm developing an application that is a mixture of two types of
executables: the "parent" file is written in C# and the "child" is written
in C++. I need to have some basic communication from the parent to the
child. I've looked into calling SendMessage and PostMessage, but I just
can't seem to find exactly what I'm looking for. And, unfortunately (as
usual), I need to have it yesterday. Here's what I'm trying to do.

The child app is started automatically upon a reboot of the device. Then,
the parent app is started. The child app is a specialized communication
system that, at this point, must be written in C++ (using eVC4). The parent
app (written in VCS2003) contains a button ([File Transfer]) that packages
the data in an XML file and adds it to a "queue". Then, it starts the comm
process (child app) if it isn't already running. All of this takes place
when the device is docked in a special cradle.

I need to be able to:

1) Get the "application" handle of the child, if it exists; or create the
process and get the handle (starting a child app seems to work with no
problem). The message functions require an HWND, which I believe is the
same as an IntPtr, but I'm unable to properly convert/use it.

2) Send a message to the child app to tell it to minimize or maximize. In
other words, I want it to "sleep" in the background until it's needed, and
then become visible.

Caveats:

I am doing this with Windows CE Pocket PC version 4.20. I'm also using CF
1.0. I also have OpenNETCF 1.4 available. I can't seem to get CF 2.0 to
work on this hardware/OS.

Can someone...anyone...explain to me how this is done, or point me to a
resource?
 
P

Paul G. Tobey [eMVP]

The easiest way to find the window handle of another process' main window is
to use FindWindow() with the name of the window. That's not an application
handle, and you should understand what a window handle is and why that's
what you're using before you continue. You'll end up in a huge hole if you
think you can gloss over the specifics. The handle is a 32-bit value, so
when P/Invoking a function that requires one, you can declare the parameter
as IntPtr, uint, int or whatever the heck you want, as long as it's a 32-bit
value parameter.

SendMessage( hwnd, WM_MINIMIZE)
SendMessage( hwnd, WM_RESTORE [or maybe WM_MAXIMIZE; see what works])

I think you'd be better off, however, to establish a custom window message,
using RegisterWindowMessage(). Pick a name for this message (a string),
that both apps can agree on. On startup, they'd both call
RegisterWindowMessage with the same string. The C++ application would then
check for this message in the window procedure for its top-level window and
interpret the parameters according to some agreed-upon semantic set.

When the C# program wants the native program to start processing, it would
send the registered window message to *all* top-level windows, thus avoiding
needing to find a specific window handle. You could have various values for
the wParam parameter with the message indicating the sort of things that you
might want the native code to do (probably *not* "minimize", "maximize", but
more like "start processing", "done with new queue items", etc., allowing
the native code to decide how to react to those commands, whether to display
UI, etc.).

I don't know what this is, "Windows CE Pocket PC version 4.20", but it
doesn't describe something that exists in reality. If the device is a
Pocket PC device, then it will run .NET CF 2.0. If it's a Windows CE 4.2
device that is not a Pocket PC, then it requires .NET CF 2.0SP1 to run 2.0
applications.

Paul T.

Kevin said:
First off, thanks to everyone in all groups for helping in the past.

I'm developing an application that is a mixture of two types of
executables: the "parent" file is written in C# and the "child" is written
in C++. I need to have some basic communication from the parent to the
child. I've looked into calling SendMessage and PostMessage, but I just
can't seem to find exactly what I'm looking for. And, unfortunately (as
usual), I need to have it yesterday. Here's what I'm trying to do.

The child app is started automatically upon a reboot of the device. Then,
the parent app is started. The child app is a specialized communication
system that, at this point, must be written in C++ (using eVC4). The
parent
app (written in VCS2003) contains a button ([File Transfer]) that packages
the data in an XML file and adds it to a "queue". Then, it starts the comm
process (child app) if it isn't already running. All of this takes place
when the device is docked in a special cradle.

I need to be able to:

1) Get the "application" handle of the child, if it exists; or create the
process and get the handle (starting a child app seems to work with no
problem). The message functions require an HWND, which I believe is the
same as an IntPtr, but I'm unable to properly convert/use it.

2) Send a message to the child app to tell it to minimize or maximize. In
other words, I want it to "sleep" in the background until it's needed, and
then become visible.

Caveats:

I am doing this with Windows CE Pocket PC version 4.20. I'm also using CF
1.0. I also have OpenNETCF 1.4 available. I can't seem to get CF 2.0 to
work on this hardware/OS.

Can someone...anyone...explain to me how this is done, or point me to a
resource?
 
K

Kevin

Thanks for the advice. I think that will at least get me going in the right
direction.

As for the PPC version, here is what the device says:

Microsoft(R) Pocket PC
Version 4.20.0 (Build 14053)
(C) 1996 (blah blah blah)

Processor: ARM PXA255
Memory: 58.68 MB
Expansion slot: In use

This is an Intermec CN2B device. I tried installin CF2 on it, but it said
something about things not running right when it installed. I'll try CF2
SP1 and see if that makes a difference. My world would be a much better
place if I could use CF2. If I can get it to work, I might also use
OpenNETCF 2.0.

Thanks again,
Kevin



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in
The easiest way to find the window handle of another process' main
window is to use FindWindow() with the name of the window. That's not
an application handle, and you should understand what a window handle
is and why that's what you're using before you continue. You'll end
up in a huge hole if you think you can gloss over the specifics. The
handle is a 32-bit value, so when P/Invoking a function that requires
one, you can declare the parameter as IntPtr, uint, int or whatever
the heck you want, as long as it's a 32-bit value parameter.

SendMessage( hwnd, WM_MINIMIZE)
SendMessage( hwnd, WM_RESTORE [or maybe WM_MAXIMIZE; see what works])

I think you'd be better off, however, to establish a custom window
message, using RegisterWindowMessage(). Pick a name for this message
(a string), that both apps can agree on. On startup, they'd both call
RegisterWindowMessage with the same string. The C++ application would
then check for this message in the window procedure for its top-level
window and interpret the parameters according to some agreed-upon
semantic set.

When the C# program wants the native program to start processing, it
would send the registered window message to *all* top-level windows,
thus avoiding needing to find a specific window handle. You could
have various values for the wParam parameter with the message
indicating the sort of things that you might want the native code to
do (probably *not* "minimize", "maximize", but more like "start
processing", "done with new queue items", etc., allowing the native
code to decide how to react to those commands, whether to display UI,
etc.).

I don't know what this is, "Windows CE Pocket PC version 4.20", but it
doesn't describe something that exists in reality. If the device is a
Pocket PC device, then it will run .NET CF 2.0. If it's a Windows CE
4.2 device that is not a Pocket PC, then it requires .NET CF 2.0SP1 to
run 2.0 applications.

Paul T.

Kevin said:
First off, thanks to everyone in all groups for helping in the past.

I'm developing an application that is a mixture of two types of
executables: the "parent" file is written in C# and the "child" is
written in C++. I need to have some basic communication from the
parent to the child. I've looked into calling SendMessage and
PostMessage, but I just can't seem to find exactly what I'm looking
for. And, unfortunately (as usual), I need to have it yesterday.
Here's what I'm trying to do.

The child app is started automatically upon a reboot of the device.
Then, the parent app is started. The child app is a specialized
communication system that, at this point, must be written in C++
(using eVC4). The parent
app (written in VCS2003) contains a button ([File Transfer]) that
packages the data in an XML file and adds it to a "queue". Then, it
starts the comm process (child app) if it isn't already running. All
of this takes place when the device is docked in a special cradle.

I need to be able to:

1) Get the "application" handle of the child, if it exists; or create
the process and get the handle (starting a child app seems to work
with no problem). The message functions require an HWND, which I
believe is the same as an IntPtr, but I'm unable to properly
convert/use it.

2) Send a message to the child app to tell it to minimize or
maximize. In other words, I want it to "sleep" in the background
until it's needed, and then become visible.

Caveats:

I am doing this with Windows CE Pocket PC version 4.20. I'm also
using CF 1.0. I also have OpenNETCF 1.4 available. I can't seem to
get CF 2.0 to work on this hardware/OS.

Can someone...anyone...explain to me how this is done, or point me to
a resource?
 
P

Paul G. Tobey [eMVP]

So, it's a PPC device, then, either 2003 or 2003SE. .NET CF 2.0 is
certainly supported on it. Contact the vendor, if install doesn't work...

Paul T.

Kevin said:
Thanks for the advice. I think that will at least get me going in the
right
direction.

As for the PPC version, here is what the device says:

Microsoft(R) Pocket PC
Version 4.20.0 (Build 14053)
(C) 1996 (blah blah blah)

Processor: ARM PXA255
Memory: 58.68 MB
Expansion slot: In use

This is an Intermec CN2B device. I tried installin CF2 on it, but it said
something about things not running right when it installed. I'll try CF2
SP1 and see if that makes a difference. My world would be a much better
place if I could use CF2. If I can get it to work, I might also use
OpenNETCF 2.0.

Thanks again,
Kevin



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in
The easiest way to find the window handle of another process' main
window is to use FindWindow() with the name of the window. That's not
an application handle, and you should understand what a window handle
is and why that's what you're using before you continue. You'll end
up in a huge hole if you think you can gloss over the specifics. The
handle is a 32-bit value, so when P/Invoking a function that requires
one, you can declare the parameter as IntPtr, uint, int or whatever
the heck you want, as long as it's a 32-bit value parameter.

SendMessage( hwnd, WM_MINIMIZE)
SendMessage( hwnd, WM_RESTORE [or maybe WM_MAXIMIZE; see what works])

I think you'd be better off, however, to establish a custom window
message, using RegisterWindowMessage(). Pick a name for this message
(a string), that both apps can agree on. On startup, they'd both call
RegisterWindowMessage with the same string. The C++ application would
then check for this message in the window procedure for its top-level
window and interpret the parameters according to some agreed-upon
semantic set.

When the C# program wants the native program to start processing, it
would send the registered window message to *all* top-level windows,
thus avoiding needing to find a specific window handle. You could
have various values for the wParam parameter with the message
indicating the sort of things that you might want the native code to
do (probably *not* "minimize", "maximize", but more like "start
processing", "done with new queue items", etc., allowing the native
code to decide how to react to those commands, whether to display UI,
etc.).

I don't know what this is, "Windows CE Pocket PC version 4.20", but it
doesn't describe something that exists in reality. If the device is a
Pocket PC device, then it will run .NET CF 2.0. If it's a Windows CE
4.2 device that is not a Pocket PC, then it requires .NET CF 2.0SP1 to
run 2.0 applications.

Paul T.

Kevin said:
First off, thanks to everyone in all groups for helping in the past.

I'm developing an application that is a mixture of two types of
executables: the "parent" file is written in C# and the "child" is
written in C++. I need to have some basic communication from the
parent to the child. I've looked into calling SendMessage and
PostMessage, but I just can't seem to find exactly what I'm looking
for. And, unfortunately (as usual), I need to have it yesterday.
Here's what I'm trying to do.

The child app is started automatically upon a reboot of the device.
Then, the parent app is started. The child app is a specialized
communication system that, at this point, must be written in C++
(using eVC4). The parent
app (written in VCS2003) contains a button ([File Transfer]) that
packages the data in an XML file and adds it to a "queue". Then, it
starts the comm process (child app) if it isn't already running. All
of this takes place when the device is docked in a special cradle.

I need to be able to:

1) Get the "application" handle of the child, if it exists; or create
the process and get the handle (starting a child app seems to work
with no problem). The message functions require an HWND, which I
believe is the same as an IntPtr, but I'm unable to properly
convert/use it.

2) Send a message to the child app to tell it to minimize or
maximize. In other words, I want it to "sleep" in the background
until it's needed, and then become visible.

Caveats:

I am doing this with Windows CE Pocket PC version 4.20. I'm also
using CF 1.0. I also have OpenNETCF 1.4 available. I can't seem to
get CF 2.0 to work on this hardware/OS.

Can someone...anyone...explain to me how this is done, or point me to
a resource?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top