Skip to content

Commit 8637586

Browse files
committed
Remove ReferenceCountedObject parent class for simplicity
1 parent ab6fcc5 commit 8637586

3 files changed

Lines changed: 41 additions & 53 deletions

File tree

CSExeCOMServer/CSExeCOMServer.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
<Compile Include="IClassFactory.cs" />
9090
<Compile Include="ISimpleObject.cs" />
9191
<Compile Include="ISimpleObjectEvents.cs" />
92-
<Compile Include="ReferenceCountedObject.cs" />
9392
<Compile Include="SimpleObject.cs" />
9493
<Compile Include="ExecutableComServer.cs" />
9594
<Compile Include="NativeMethods.cs" />

CSExeCOMServer/ReferenceCountedObject.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

CSExeCOMServer/SimpleObject.cs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,21 @@
4444
namespace CSExeCOMServer
4545
{
4646
[ComVisible(true)]
47-
[Guid("DB9935C1-19C5-4ed2-ADD2-9A57E19F53A3")]
4847
[ClassInterface(ClassInterfaceType.None)] // No ClassInterface
48+
[Guid("DB9935C1-19C5-4ed2-ADD2-9A57E19F53A3")]
4949
[ComSourceInterfaces(typeof(ISimpleObjectEvents))]
50-
public class SimpleObject : ReferenceCountedObject, ISimpleObject
50+
public class SimpleObject : ISimpleObject
5151
{
52-
// These routines perform the additional COM registration needed by
53-
// the service.
54-
55-
[ComRegisterFunction]
56-
[EditorBrowsable(EditorBrowsableState.Never)]
57-
public static void Register(Type t)
52+
public SimpleObject()
5853
{
59-
try
60-
{
61-
HelperMethods.RegasmRegisterLocalServer(t);
62-
}
63-
catch (Exception ex)
64-
{
65-
Console.WriteLine(ex.Message); // Log the error
66-
throw ex; // Re-throw the exception
67-
}
54+
// Increment the lock count of objects in the COM server.
55+
ExecutableComServer.Instance.Lock();
6856
}
6957

70-
[ComUnregisterFunction]
71-
[EditorBrowsable(EditorBrowsableState.Never)]
72-
public static void Unregister(Type t)
58+
~SimpleObject()
7359
{
74-
try
75-
{
76-
HelperMethods.RegasmUnregisterLocalServer(t);
77-
}
78-
catch (Exception ex)
79-
{
80-
Console.WriteLine(ex.Message); // Log the error
81-
throw ex; // Re-throw the exception
82-
}
60+
// Decrement the lock count of objects in the COM server.
61+
ExecutableComServer.Instance.Unlock();
8362
}
8463

8564
private float fField = 0f;
@@ -113,5 +92,38 @@ public void GetProcessThreadId(out int processId, out int threadId)
11392
public delegate void FloatPropertyChangingEventHandler(float NewValue, ref bool Cancel);
11493

11594
public event FloatPropertyChangingEventHandler FloatPropertyChanging;
95+
96+
// These routines perform the additional COM registration needed by
97+
// the service.
98+
99+
[ComRegisterFunction]
100+
[EditorBrowsable(EditorBrowsableState.Never)]
101+
public static void Register(Type t)
102+
{
103+
try
104+
{
105+
HelperMethods.RegasmRegisterLocalServer(t);
106+
}
107+
catch (Exception ex)
108+
{
109+
Console.WriteLine(ex.Message); // Log the error
110+
throw ex; // Re-throw the exception
111+
}
112+
}
113+
114+
[ComUnregisterFunction]
115+
[EditorBrowsable(EditorBrowsableState.Never)]
116+
public static void Unregister(Type t)
117+
{
118+
try
119+
{
120+
HelperMethods.RegasmUnregisterLocalServer(t);
121+
}
122+
catch (Exception ex)
123+
{
124+
Console.WriteLine(ex.Message); // Log the error
125+
throw ex; // Re-throw the exception
126+
}
127+
}
116128
}
117129
}

0 commit comments

Comments
 (0)