如何在.NET EXE 和 COM EXE 之间进行通信?

发布于 2024-08-17 01:29:37 字数 244 浏览 2 评论 0原文

我在 Windows Mobile 中有一个 .NET EXE 和 ATL COM EXE。他们之间我需要沟通。 即我的 ATL EXE 启动 .NET EXE。 .NET EXE 应向 ATL EXE 发送一条消息,表明处理已完成或退出。我怎样才能做到这一点?

两个独立进程之间如何通信?

I have a .NET EXE and ATL COM EXE in Windows Mobile. I need to communicate between them.
I.e my ATL EXE launches the .NET EXE. The .NET EXE should send a message to the ATL EXE that the processing is completed or exited. How can I do that?

How to communicate between the two separate process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

和影子一齐双人舞 2024-08-24 01:29:37

CreateProcess可以返回进程句柄。您所要做的就是 WaitForSinbleObject ,当 .NET 进程退出时,它将收到信号。

CreateProcess can return the process handle. All you have to do is WaitForSinbleObject on it, it will be signaled when the .NET process exits.

池木 2024-08-24 01:29:37

编辑:

错过了这个问题是关于移动设备的。不知道这是否有效。

我将 IPC 通道与此帮助程序类一起使用:

static class IpcChannelManager<T> {
   /// <summary>
   /// Make a type available to other processess
   /// </summary>
   /// <param name="type">
   /// Type to register, must derive from MarshalByRefObject and implement <typeparamref name="T"/>
   /// </param>
   /// <param name="portName">Name of IpcChannel</param>
   public static void RegisterType(Type type, string portName) {
       if (!type.IsSubclassOf(typeof(MarshalByRefObject)))
           throw new ArgumentException("Registered type must derive from MarshalByRefObject");
       Dictionary<string, string> ipcproperties = new Dictionary<string, string>();
       ipcproperties["portName"] = portName;
       // Get the localized name of the "Authenticated users" group
       ipcproperties["authorizedGroup"] = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null).Translate(typeof(NTAccount)).ToString();

        ChannelServices.RegisterChannel(new IpcServerChannel(ipcproperties, null), false);
        RemotingConfiguration.RegisterWellKnownServiceType(type, typeof(T).Name, WellKnownObjectMode.Singleton);
    }

    /// <summary>
    /// Get a reference to a remoting object
    /// </summary>
    /// <param name="portName">Name of Ipc port</param>
    /// <returns>
    /// Reference to remote server object</returns>
    public static T GetRemoteProxy(string portName) {
        ChannelServices.RegisterChannel(new IpcClientChannel(), false);
        return (T)Activator.GetObject(typeof(T), "ipc://" + portName + "/" + typeof(T).Name);
}

然后我像这样使用它:

双方都可用的接口

interface IIpcMessage {
    int GetSomeData(string foo);
}

在接收端我做

class IpcMessage : MarshalByRefObject, IIpcMessage {
    ...
 }

 IpcChannelManager<IIpcMessage>.RegisterType(typeof(IpcMessage), "Someuniqueportname");

并且在发送端:

 IIpcMessage ipcMessage = IpcChannelManager<IIpcMessage>.GetRemoteProxy("Someuniqueportname");

 int data = ipcMessage.GetSomeDate("blabla");

Edit:

Missed that the question was about mobile. Don't know if this works.

I use an IPC channel with this helper class:

static class IpcChannelManager<T> {
   /// <summary>
   /// Make a type available to other processess
   /// </summary>
   /// <param name="type">
   /// Type to register, must derive from MarshalByRefObject and implement <typeparamref name="T"/>
   /// </param>
   /// <param name="portName">Name of IpcChannel</param>
   public static void RegisterType(Type type, string portName) {
       if (!type.IsSubclassOf(typeof(MarshalByRefObject)))
           throw new ArgumentException("Registered type must derive from MarshalByRefObject");
       Dictionary<string, string> ipcproperties = new Dictionary<string, string>();
       ipcproperties["portName"] = portName;
       // Get the localized name of the "Authenticated users" group
       ipcproperties["authorizedGroup"] = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null).Translate(typeof(NTAccount)).ToString();

        ChannelServices.RegisterChannel(new IpcServerChannel(ipcproperties, null), false);
        RemotingConfiguration.RegisterWellKnownServiceType(type, typeof(T).Name, WellKnownObjectMode.Singleton);
    }

    /// <summary>
    /// Get a reference to a remoting object
    /// </summary>
    /// <param name="portName">Name of Ipc port</param>
    /// <returns>
    /// Reference to remote server object</returns>
    public static T GetRemoteProxy(string portName) {
        ChannelServices.RegisterChannel(new IpcClientChannel(), false);
        return (T)Activator.GetObject(typeof(T), "ipc://" + portName + "/" + typeof(T).Name);
}

And then I use it like this:

An interface available on both sides

interface IIpcMessage {
    int GetSomeData(string foo);
}

On the receiving end I do

class IpcMessage : MarshalByRefObject, IIpcMessage {
    ...
 }

 IpcChannelManager<IIpcMessage>.RegisterType(typeof(IpcMessage), "Someuniqueportname");

And on the sender end:

 IIpcMessage ipcMessage = IpcChannelManager<IIpcMessage>.GetRemoteProxy("Someuniqueportname");

 int data = ipcMessage.GetSomeDate("blabla");
饮湿 2024-08-24 01:29:37

您可以使用 Windows 消息。有关详细信息,请参阅此博客文章

You could use Windows Messages. See this blog post for details.

夜血缘 2024-08-24 01:29:37

使用点对点消息队列(请参阅 CreateMsgQueue API)。

Use a point to point message queue (see the CreateMsgQueue API).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文