views:

172

answers:

4

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?

A: 

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

kgiannakakis
Hey i tried using window messages, its fine if we have single window of a particular name..but what if we have multiple window of same name?
Shadow
+1  A: 

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");
adrianm
This will not work under Windows Mobile/Windows CE
ctacke
+1  A: 

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

Hans Passant
hey should we able to pass the event handle in command line..is it possible?
Shadow
Yes, you can pass stuff on the command line. Not handle values however, their values are only valid in the process that created them.
Hans Passant
Hey.. in command line we can pass string right..how can we able to pass the event handle..can u please tell me
Shadow
I'll repeat: you can't. You don't have to, everything I described happens only in the ATL program.
Hans Passant
A: 

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

ctacke