By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

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

P: n/a
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,
Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"dthom" <no********@nospamthanks.nu> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?
Nov 17 '05 #2

P: n/a
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
"dthom" <no********@nospamthanks.nu> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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,

Nov 17 '05 #3

P: n/a
Sometimes, socket is not as hard as you imagine, and I would suggest you
go that approach.

Jianwei
dthom wrote:
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,

Nov 17 '05 #4

P: n/a
"Gabriel Lozano-Mor√°n" wrote:
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
"dthom" <no********@nospamthanks.nu> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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,


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);

Nov 17 '05 #5

P: n/a
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++.

Nov 17 '05 #6

P: n/a
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.
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> skrev i en meddelelse
news:O0*************@TK2MSFTNGP09.phx.gbl...
"dthom" <no********@nospamthanks.nu> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?

Nov 17 '05 #7

P: n/a
I'd use a socket.

Nov 17 '05 #8

P: n/a
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
"dthom" wrote:
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++.

Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.