/// <summary> /// Add an Event Subscription object to an Event Server /// </summary> /// <param name="bActive">FALSE if the Event Subscription is to be created inactive and TRUE if it is to be created as active.</param> /// <param name="dwBufferTime">The requested buffer time. The buffer time is in milliseconds and tells the server how often to send event notifications. A value of 0 for dwBufferTime means that the server should send event notifications as soon as it gets them.</param> /// <param name="dwMaxSize">The requested maximum number of events that will be sent in a single IOPCEventSink::OnEvent callback. A value of 0 means that there is no limit to the number of events that will be sent in a single callback.</param> /// <param name="hClientSubscription">Client provided handle for this event subscription.</param> /// <param name="riid">The type of interface desired</param> /// <param name="ppUnk">Where to store the returned interface pointer.</param> /// <param name="pdwRevisedBufferTime">The buffer time that the server is actually providing, which may differ from dwBufferTime.</param> /// <param name="pdwRevisedMaxSize">The maximum number of events that the server will actually be sending in a single IOPCEventSink::OnEvent callback, which may differ from dwMaxSize.</param> public void CreateEventSubscription(int bActive, int dwBufferTime, int dwMaxSize, int hClientSubscription, ref Guid riid, out object ppUnk, out int pdwRevisedBufferTime, out int pdwRevisedMaxSize) { ppUnk = IntPtr.Zero; pdwRevisedBufferTime = 0; pdwRevisedMaxSize = 0; IntPtr pbActive = IntPtr.Zero; IntPtr pdwBufferTime = IntPtr.Zero; IntPtr pdwMaxSize = IntPtr.Zero; Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); try { Subscription subscription = new Subscription(this); if (subscription == null) throw ComUtils.CreateComException("E_OUTOFMEMORY", ResultIds.E_OUTOFMEMORY); SubscriptionListInsert(subscription); pbActive = Marshal.AllocHGlobal(Marshal.SizeOf(bActive.GetType())); pdwBufferTime = Marshal.AllocHGlobal(Marshal.SizeOf(dwBufferTime.GetType())); pdwMaxSize = Marshal.AllocHGlobal(Marshal.SizeOf(dwMaxSize.GetType())); Marshal.WriteInt32(pbActive, bActive); Marshal.WriteInt32(pdwBufferTime, dwBufferTime); Marshal.WriteInt32(pdwMaxSize, dwMaxSize); subscription.SetState(pbActive, pdwBufferTime, pdwMaxSize, hClientSubscription, out pdwRevisedBufferTime, out pdwRevisedMaxSize); subscription.UaSubscription = m_Subscription; ppUnk = subscription; } catch (Exception e) { Utils.Trace(e, "Unexpected error in CreateEventSubscription"); throw ComUtils.CreateComException(e); } finally { if (pbActive != IntPtr.Zero) Marshal.FreeHGlobal(pbActive); if (pdwBufferTime != IntPtr.Zero) Marshal.FreeHGlobal(pdwBufferTime); if (pdwMaxSize != IntPtr.Zero) Marshal.FreeHGlobal(pdwMaxSize); } }