exchanging data between a win32 application (service) and a c# application (service)

D

dthom

Hi,

I have a C# service application - and a Win32 / C++ service application
running on my system.

I need someway to interact between those two - the Win32 application is pure
Win32 - so im not using any components or anything like that.

The 2 alternatives i could think of was, messages or creating a TCP/IP
socketserver on the C# end, so i could control it that way.

The socket approach is abit overkill i feel - but i do need to be able to
transfer data packets somehow ?

I am not that sharp in C# - do anybody know how to do this the smartest way
?

Thanx,
 
M

Mark Rae

I need someway to interact between those two

Please be a bit more specific about what you mean by "interact".

Do you want both apps to share data?

Do you want both apps to be able to start / stop the other?

Do you want one app to "monitor" the activity of the other somehow?
 
G

Gabriel Lozano-Morán

Depening on what you want you can either use XML Webservices, .NET Remoting
or DCOM

If you can be more specific about what you want and it wil run on your
intranet or not, ... I'm pretty sure that people here can provide feedback

Gabriel Lozano-Morán
 
J

Jianwei Sun

Sometimes, socket is not as hard as you imagine, and I would suggest you
go that approach.
 
G

Guest

Gabriel Lozano-Morán said:
Depening on what you want you can either use XML Webservices, .NET Remoting
or DCOM

If you can be more specific about what you want and it wil run on your
intranet or not, ... I'm pretty sure that people here can provide feedback

Gabriel Lozano-Morán

I may be working on the same problem and am trying to use Interop. Both
processes are on the same CPU. One is a C# Windows Applications using Windows
Forms. The other is a C++ application written to the Win32 SDK and interfaces
with the serial port using SetCommMask, WaitCommEvent,
WaitForMultipleObjects, and GetCommModemStatus.

My plan is to merge them into one process with two different threads of
execution.

My suggestion is to look at using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam,
IntPtr lParam);
 
D

dthom

Well to clarify, it is simple two applications (running as services) running
on the same PC.

Thats also why i find socketcommunciation to and from localhost abit
overkill - its not that its hard (the PC applications is in fact a
socketserver) - but i just hoped there was somekind of messaging system /
memory-mapped-file similiar kindof sharing data between processes.

The problem ofcourse, the one is CSharp, the other is C++ - and i dont have
the full overview over CSharp as i do with C++.
 
D

dthom

Well by interact i mean:

1. Send a COMMAND, and a datablock with data (to be used by the client)
2. Recieve a COMMAND (normally an answer on a previously sent command)

I would prefer both data to be able to share data yes.

I dont need to start / stop the other - but it could be an issue from my C++
application to at least start the cSharp application at some point (of it
goes ballistic).

No monitoring - the CSharp is handling communication to a special device, in
a way that i cannot incooporate in my C++ application (which is a very very
crucial application that handles alot of tasks) - in the CSharp i dont have
the full overview over the code lying beneath since its using 3.rd. party
products - therefore it is a demand that this application is seperated from
the very critical serverapplication.

So if the CSharp applications crashes bigtime, it doesnt affect my C++
application - thats the main reason - the secondary is that it would be a
huge job to incooperate the functionality from the CSharp into the server.
 
G

Guest

My suggestion is to look at using System.Runtime.InteropServices;
Here is some code that I wrote to send a message to another process on the
same box.
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

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

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);

private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
if (checkBox1.Checked)
{
IntPtr handle = FindWindow(null, "xxx Monitor");
if(handle != IntPtr.Zero)
{
uint x_GenerateEvent = RegisterWindowMessage("ZM_GenerateEvent");
SendMessage(handle, x_GenerateEvent, UIntPtr.Zero, IntPtr.Zero);

int attempts = 0;
while (attempts < 5)
{
Thread.Sleep(1000); // allow the file to be created by other process
if (WorkOnFile() == true)
break;
attempts++;
}
if (attempts == 5)
{
MessageBox.Show("file not found by WorkOnFile()");
}
else
{
checkBox1.Checked = false;
}
}
else
{
MessageBox.Show("Cannot find xxx Monitor window");
}
}
}

Note: The "xxx Monitor" process written in C creates a file after I send a
message.

hope it helps --tony
 
Z

zabutimaxim

Hi,

You can use Memory Mapped File pattern.
The advantage is that it will work very fast, but
disadvantage that it is little complicated to implement, because
of .NET and Win32 incompatibility of data types, but try
to use following component, maybe it will help you:
http://www.winterdom.com/dev/dotnet/
download the FileMap component there

Regards,
Zabuti Maxim
 

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