-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathSimpleCOMObject.cs
More file actions
81 lines (70 loc) · 2.61 KB
/
Copy pathSimpleCOMObject.cs
File metadata and controls
81 lines (70 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms; // For using MessageBox.
using Interop.SimpleCOMObject; // In order to implement ISimpleCOMObject.
using System.Runtime.InteropServices; // For use of the GuidAttribute, ProgIdAttribute and ClassInterfaceAttribute.
namespace XAPI.COM
{
/// <summary>
/// Summary description for SimpleCOMObject.
/// This is the class that will be exported to unmanaged COM client apps.
/// </summary>
[
Guid("E1FE1223-45C2-4872-9B1E-634FB850E753"), // We indicate a specific CLSID for "ManagedCOMLocalServer_Impl01.SimpleCOMObject" for convenience of searching the registry.
ProgId("ManagedCOMLocalServer_Impl01.SimpleCOMObject"), // This ProgId is used by default. Not 100% necessary.
ClassInterface(ClassInterfaceType.None) // Specify that we will not generate any additional interface with a name like _SimpleCOMObject.
]
public class SimpleCOMObject :
ReferenceCountedObjectBase, // SimpleCOMObject is derived from ReferenceCountedObjectBase so that we can track its creation and destruction.
ISimpleCOMObject // SimpleCOMObject must implement the ISimpleCOMObject interface.
{
private int m_iLongProperty;
public SimpleCOMObject()
{
// ReferenceCountedObjectBase constructor will be invoked.
Console.WriteLine("SimpleCOMObject constructor.");
}
~SimpleCOMObject()
{
// ReferenceCountedObjectBase destructor will be invoked.
Console.WriteLine("SimpleCOMObject destructor.");
}
public int LongProperty
{
get
{
return m_iLongProperty;
}
set
{
m_iLongProperty = value;
}
}
public void Method01 (String strMessage)
{
StringBuilder sb = new StringBuilder(strMessage);
sb.Append(LongProperty.ToString());
MessageBox.Show(sb.ToString(), "ManagedCOMLocalServer_Impl01.SimpleCOMObject");
}
}
//class SimpleCOMObjectClassFactory : ClassFactoryBase
//{
// public override void virtual_CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)
// {
// Console.WriteLine("SimpleCOMObjectClassFactory.CreateInstance().");
// Console.WriteLine("Requesting Interface : " + riid.ToString());
// if (riid == Marshal.GenerateGuidForType(typeof(ISimpleCOMObject)) ||
// riid == ManagedCOMLocalServer.IID_IDispatch ||
// riid == ManagedCOMLocalServer.IID_IUnknown)
// {
// SimpleCOMObject SimpleCOMObject_New = new SimpleCOMObject();
// ppvObject = Marshal.GetComInterfaceForObject(SimpleCOMObject_New, typeof(ISimpleCOMObject));
// }
// else
// {
// throw new COMException("No interface", unchecked((int) 0x80004002));
// }
// }
//}
}