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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dthom

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

    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,


  • Mark Rae

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

    "dthom" <nospamspam@nos pamthanks.nu> wrote in message
    news:%236eqnXRO FHA.2728@TK2MSF TNGP15.phx.gbl. ..
    [color=blue]
    > I need someway to interact between those two[/color]

    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?


    Comment

    • Gabriel Lozano-Morán

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

      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" <nospamspam@nos pamthanks.nu> wrote in message
      news:%236eqnXRO FHA.2728@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      > 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,
      >[/color]


      Comment

      • Jianwei Sun

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

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

        Jianwei
        dthom wrote:[color=blue]
        > 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,
        >
        >[/color]

        Comment

        • Tony

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

          "Gabriel Lozano-Morán" wrote:
          [color=blue]
          > 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" <nospamspam@nos pamthanks.nu> wrote in message
          > news:%236eqnXRO FHA.2728@TK2MSF TNGP15.phx.gbl. ..[color=green]
          > > 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,
          > >[/color]
          >[/color]

          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,
          WaitForMultiple Objects, and GetCommModemSta tus.

          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("user 32.dll")]
          static extern IntPtr SendMessage(Int Ptr hWnd, uint Msg, UIntPtr wParam,
          IntPtr lParam);

          Comment

          • dthom

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

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

            Thats also why i find socketcommuncia tion 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++.



            Comment

            • dthom

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

              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 serverapplicati on.

              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" <mark@mark-N-O-S-P-A-M-rae.co.uk> skrev i en meddelelse
              news:O0nWWcROFH A.940@TK2MSFTNG P09.phx.gbl...[color=blue]
              > "dthom" <nospamspam@nos pamthanks.nu> wrote in message
              > news:%236eqnXRO FHA.2728@TK2MSF TNGP15.phx.gbl. ..
              >[color=green]
              >> I need someway to interact between those two[/color]
              >
              > 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?
              >[/color]


              Comment

              • stork

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

                I'd use a socket.

                Comment

                • Tony

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

                  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("user 32.dll")]
                  static extern IntPtr FindWindow(stri ng lpClassName, string lpWindowName);

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

                  [DllImport("user 32.dll", SetLastError=tr ue, CharSet=CharSet .Auto)]
                  static extern uint RegisterWindowM essage(string lpString);

                  private void checkBox1_Check edChanged(objec t sender, System.EventArg s e)
                  {
                  if (checkBox1.Chec ked)
                  {
                  IntPtr handle = FindWindow(null , "xxx Monitor");
                  if(handle != IntPtr.Zero)
                  {
                  uint x_GenerateEvent = RegisterWindowM essage("ZM_Gene rateEvent");
                  SendMessage(han dle, x_GenerateEvent , UIntPtr.Zero, IntPtr.Zero);

                  int attempts = 0;
                  while (attempts < 5)
                  {
                  Thread.Sleep(10 00); // 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.Check ed = 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:
                  [color=blue]
                  > Well to clarify, it is simple two applications (running as services) running
                  > on the same PC.
                  >
                  > Thats also why i find socketcommuncia tion 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++.
                  >
                  >
                  >
                  >[/color]

                  Comment

                  Working...