internal extern static int PeerCollabRegisterApplication(ref PEER_APPLICATION_REGISTRATION_INFO appRegInfo, PeerApplicationRegistrationType appRegType);
public static void RegisterApplication(PeerApplication application, PeerApplicationRegistrationType type) { PeerCollaborationPermission.UnrestrictedPeerCollaborationPermission.Demand(); if (application == null){ throw new ArgumentNullException("application"); } if (application.Path == null){ throw new ArgumentException(SR.GetString(SR.Collab_AppRegNoPathError)); } if ((type < PeerApplicationRegistrationType.CurrentUser) || (type > PeerApplicationRegistrationType.AllUsers)){ throw new ArgumentOutOfRangeException("type"); } CollaborationHelperFunctions.Initialize(); int errorCode = 0; // // Convert PeerApplication.Guid into native GUID struct // PEER_APPLICATION_REGISTRATION_INFO appRegInfo = new PEER_APPLICATION_REGISTRATION_INFO(); appRegInfo.application.guid = CollaborationHelperFunctions.ConvertGuidToGUID(application.Id); appRegInfo.pwzApplicationArguments = application.CommandLineArgs; appRegInfo.pwzApplicationToLaunch = application.Path; appRegInfo.dwPublicationScope = (uint)application.PeerScope; if (Logging.P2PTraceSource.Switch.ShouldTrace(TraceEventType.Information)){ Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "RegisterApplication() is called with the following Info"); application.TracePeerApplication(); } unsafe{ SafeCollabMemory data = null; appRegInfo.application.data.cbData = (application.Data!=null) ? (UInt32)application.Data.Length : 0; GCHandle descHandle = new GCHandle(); try{ // // Marshal any data to send to native call // if ((application.Data!=null) && (application.Data.Length > 0)) { data = new SafeCollabMemory(application.Data.Length); appRegInfo.application.data.pbData = data.DangerousGetHandle(); Marshal.Copy(application.Data, 0, appRegInfo.application.data.pbData, application.Data.Length); } else appRegInfo.application.data.pbData = IntPtr.Zero; descHandle = GCHandle.Alloc(application.Description, GCHandleType.Pinned); appRegInfo.application.pwzDescription = descHandle.AddrOfPinnedObject(); errorCode = UnsafeCollabNativeMethods.PeerCollabRegisterApplication(ref appRegInfo, type); } finally{ if (descHandle.IsAllocated) descHandle.Free(); if (data != null) data.Dispose(); } } if (errorCode == UnsafeCollabReturnCodes.PEER_E_ALREADY_EXISTS){ Logging.P2PTraceSource.TraceEvent(TraceEventType.Error, 0, "PeerCollabRegisterApplication returned with errorcode {0}. Application already registered.", errorCode); throw new ArgumentException(SR.GetString(SR.Collab_AppRegFailed) + " " + SR.GetString(SR.Collab_AppExists)); } else if (errorCode != 0){ Logging.P2PTraceSource.TraceEvent(TraceEventType.Error, 0, "PeerCollabRegisterApplication returned with errorcode {0}", errorCode); throw (PeerToPeerException.CreateFromHr(SR.GetString(SR.Collab_AppRegFailed), errorCode)); } Logging.P2PTraceSource.TraceEvent(TraceEventType.Error, 0, "RegisterApplication successful"); }