Send / Receive Message To / From two running application

I have two applications called SENDER and RECEIVER.

RECEIVER will be launched by the SENDER method System.Diagnostics.Process.Start

RECEIVER will be launched in stealth mode, so it doesnโ€™t MainWindowHandle.

Then we could use Win32.WM_COPYDATAto send a message to RECEIVER, but for this we need MainWindowHandle, so we can not.

What I need is the ability to periodically send and receive messages in any way.

I checked the following link for a guide to MainWindowHandle, but that didn't help:

Send a message to a Windows process (not its main window)

One solution might be an object from System.Diagnostics.Process, which can help us send messages to the process.

+8
source share
4

.

-, , , .

  • TCP/UDP ( )
  • MSMQ
  • WebServices, WCF Restful Web Service.
  • db. ( )
  • ( this) ( )

.

: MSMQ

, , , , Windows, MSMQ . ?

  • MSMQ ( , RECEIVER )
  • MSMQ .
  • Windows / .
  • Windows SNMP, Windows.

: Restful Web Service

MSMQ, Restful Web Service, IIS, . , , RECEIVER SENDER, .

+14

CreateFromFile . .

using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;

class Program
{
    static void Main(string[] args)
    {
        long offset = 0x10000000; // 256 megabytes
        long length = 0x20000000; // 512 megabytes

        // Create the memory-mapped file.
        using (var mmf = MemoryMappedFile.CreateFromFile(@"c:\ExtremelyLargeImage.data", FileMode.Open,"ImgA"))
        {
            // Create a random access view, from the 256th megabyte (the offset)
            // to the 768th megabyte (the offset plus length).
            using (var accessor = mmf.CreateViewAccessor(offset, length))
            {
                int colorSize = Marshal.SizeOf(typeof(MyColor));
                MyColor color;

                // Make changes to the view.
                for (long i = 0; i < length; i += colorSize)
                {
                    accessor.Read(i, out color);
                    color.Brighten(10);
                    accessor.Write(i, ref color);
                }
            }
        }
    }
}

public struct MyColor
{
    public short Red;
    public short Green;
    public short Blue;
    public short Alpha;

    // Make the view brighter.
    public void Brighten(short value)
    {
        Red = (short)Math.Min(short.MaxValue, (int)Red + value);
        Green = (short)Math.Min(short.MaxValue, (int)Green + value);
        Blue = (short)Math.Min(short.MaxValue, (int)Blue + value);
        Alpha = (short)Math.Min(short.MaxValue, (int)Alpha + value);
    }
}

.

using System;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;


class Program
{
    static void Main(string[] args)
    {
        // Assumes another process has created the memory-mapped file.
        using (var mmf = MemoryMappedFile.OpenExisting("ImgA"))
        {
            using (var accessor = mmf.CreateViewAccessor(4000000, 2000000))
            {
                int colorSize = Marshal.SizeOf(typeof(MyColor));
                MyColor color;

                // Make changes to the view.
                for (long i = 0; i < 1500000; i += colorSize)
                {
                    accessor.Read(i, out color);
                    color.Brighten(20);
                    accessor.Write(i, ref color);
                }
            }
        }
    }
}

public struct MyColor
{
    public short Red;
    public short Green;
    public short Blue;
    public short Alpha;

    // Make the view brigher.
    public void Brighten(short value)
    {
        Red = (short)Math.Min(short.MaxValue, (int)Red + value);
        Green = (short)Math.Min(short.MaxValue, (int)Green + value);
        Blue = (short)Math.Min(short.MaxValue, (int)Blue + value);
        Alpha = (short)Math.Min(short.MaxValue, (int)Alpha + value);
    }
}
+1

, .
, .
- , , .
1. 2. , , 2. .
( Windows).

, , 2. , / , .
1. , , 2..

. , , . , .

Therefore, it probably depends on what it is for.

0
source

I think MSMQ is a good option.

-1
source

All Articles