Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ComEventsHelper.cs
Go to the documentation of this file.
2
4
5[SupportedOSPlatform("windows")]
6public static class ComEventsHelper
7{
8 public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
9 {
10 lock (rcw)
11 {
12 ComEventsInfo comEventsInfo = ComEventsInfo.FromObject(rcw);
13 ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid) ?? comEventsInfo.AddSink(ref iid);
14 ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid) ?? comEventsSink.AddMethod(dispid);
15 comEventsMethod.AddDelegate(d);
16 }
17 }
18
19 public static Delegate? Remove(object rcw, Guid iid, int dispid, Delegate d)
20 {
21 lock (rcw)
22 {
23 ComEventsInfo comEventsInfo = ComEventsInfo.Find(rcw);
24 if (comEventsInfo == null)
25 {
26 return null;
27 }
28 ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid);
29 if (comEventsSink == null)
30 {
31 return null;
32 }
33 ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid);
34 if (comEventsMethod == null)
35 {
36 return null;
37 }
38 comEventsMethod.RemoveDelegate(d);
39 if (comEventsMethod.Empty)
40 {
41 comEventsMethod = comEventsSink.RemoveMethod(comEventsMethod);
42 }
43 if (comEventsMethod == null)
44 {
45 comEventsSink = comEventsInfo.RemoveSink(comEventsSink);
46 }
47 if (comEventsSink == null)
48 {
49 Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), null);
50 GC.SuppressFinalize(comEventsInfo);
51 }
52 return d;
53 }
54 }
55}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static ? Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
static void Combine(object rcw, Guid iid, int dispid, Delegate d)
static ComEventsInfo FromObject(object rcw)
static ComEventsInfo Find(object rcw)
ComEventsSink RemoveSink(ComEventsSink sink)
void AddDelegate(Delegate d, bool wrapArgs=false)
void RemoveDelegate(Delegate d, bool wrapArgs=false)
ComEventsMethod RemoveMethod(ComEventsMethod method)
static bool SetComObjectData(object obj, object key, object? data)
Definition Marshal.cs:428