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 p开发者_运维百科rocess?
CreateProcess can return the process handle. All you have to do is WaitForSinbleObject on it, it will be signaled when the .NET process exits.
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");
You could use Windows Messages. See this blog post for details.
Use a point to point message queue (see the CreateMsgQueue API).
精彩评论