-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDrveTermWrap.cs
233 lines (205 loc) · 8.71 KB
/
DrveTermWrap.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using System.Collections.Generic;
using System.Text;
using DrveTerm;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace DrveTerm
{
[ClassInterface(ClassInterfaceType.AutoDispatch), ComVisible(true)]
public sealed class DrvCtxEventSinkHelper : _IDrvCtxEvents
{
// Fields
public int m_dwCookie = 0;
public _IDrvCtxEvents_OnAsyncDataEventHandler m_OnAsyncDataDelegate = null;
public _IDrvCtxEvents_OnNotifyEventHandler m_OnNotifyDelegate = null;
public _IDrvCtxEvents_OnStatusEventHandler m_OnStatusDelegate = null;
public _IDrvCtxEvents_OnSyncDataEventHandler m_OnSyncDataDelegate = null;
// Methods
[DispId(1)]
public void OnAsyncData(string bstrData, string bstrProperties)
{
if (this.m_OnAsyncDataDelegate != null)
{
this.m_OnAsyncDataDelegate(bstrData, bstrProperties);
}
}
[DispId(2)]
public void OnSyncData(string bstrCommand, string bstrCacheResponse, ref int lpdwRemainMultiResponse, ref string lpbstrResponse, string bstrProperties)
{
if (this.m_OnSyncDataDelegate != null)
{
this.m_OnSyncDataDelegate(bstrCommand, bstrCacheResponse, ref lpdwRemainMultiResponse, ref lpbstrResponse, bstrProperties);
}
}
[DispId(3)]
public void OnStatus(int nStatus, string bstrStatusMessage)
{
if (this.m_OnStatusDelegate != null)
{
this.m_OnStatusDelegate(nStatus, bstrStatusMessage);
}
}
[DispId(4)]
public void OnNotify(int nNotify, string bstrNotifyMessage)
{
if (this.m_OnNotifyDelegate != null)
{
this.m_OnNotifyDelegate(nNotify, bstrNotifyMessage);
}
}
}
public class DrvCtxWrap : IDisposable
{
// Fields
// Track whether Dispose has been called.
private bool disposed = false;
private IDrvCtx _drvCtx = null;
private DrvCtxEventSinkHelper _eventSinkHelper = null;
private IConnectionPoint _connectionPoint = null;
private IConnectionPointContainer _connectionPointContainer = null;
// Events
public event _IDrvCtxEvents_OnAsyncDataEventHandler _IDrvCtxEvents_Event_OnAsyncData;
public event _IDrvCtxEvents_OnNotifyEventHandler _IDrvCtxEvents_Event_OnNotify;
public event _IDrvCtxEvents_OnStatusEventHandler _IDrvCtxEvents_Event_OnStatus;
public event _IDrvCtxEvents_OnSyncDataEventHandler _IDrvCtxEvents_Event_OnSyncData;
public void OnAsyncData(string bstrData, string bstrProperties)
{
if (this._IDrvCtxEvents_Event_OnAsyncData != null)
{
this._IDrvCtxEvents_Event_OnAsyncData(bstrData, bstrProperties);
}
}
public void OnSyncData(string bstrCommand, string bstrCacheResponse, ref int lpdwRemainMultiResponse, ref string lpbstrResponse, string bstrProperties)
{
if (this._IDrvCtxEvents_Event_OnSyncData != null)
{
this._IDrvCtxEvents_Event_OnSyncData(bstrCommand, bstrCacheResponse, ref lpdwRemainMultiResponse, ref lpbstrResponse, bstrProperties);
}
}
public void OnStatus(int nStatus, string bstrStatusMessage)
{
if (this._IDrvCtxEvents_Event_OnStatus != null)
{
this._IDrvCtxEvents_Event_OnStatus(nStatus, bstrStatusMessage);
}
}
public void OnNotify(int nNotify, string bstrNotifyMessage)
{
if (this._IDrvCtxEvents_Event_OnNotify != null)
{
this._IDrvCtxEvents_Event_OnNotify(nNotify, bstrNotifyMessage);
}
}
// Methods
public DrvCtxWrap(IDrvCtx ctx)
{
try
{
this._drvCtx = ctx;
this._connectionPointContainer = (IConnectionPointContainer)ctx;
IConnectionPoint ppCP = null;
byte[] b = new byte[] { 0xe5, 0x26, 0xd6, 0x63, 0x58, 0x20, 0x18, 0x4d, 0xa2, 190, 0x52, 0x3f, 0xf5, 0x3d, 0x44, 0x34 };
Guid riid = new Guid(b);
this._connectionPointContainer.FindConnectionPoint(ref riid, out ppCP);
this._connectionPoint = (IConnectionPoint)ppCP;
this._eventSinkHelper = new DrvCtxEventSinkHelper();
this._eventSinkHelper.m_OnAsyncDataDelegate = new _IDrvCtxEvents_OnAsyncDataEventHandler(this.OnAsyncData);
this._eventSinkHelper.m_OnNotifyDelegate = new _IDrvCtxEvents_OnNotifyEventHandler(this.OnNotify);
this._eventSinkHelper.m_OnStatusDelegate = new _IDrvCtxEvents_OnStatusEventHandler(this.OnStatus);
this._eventSinkHelper.m_OnSyncDataDelegate = new _IDrvCtxEvents_OnSyncDataEventHandler(this.OnSyncData);
int pdwCookie = 0;
this._connectionPoint.Advise((object)this._eventSinkHelper, out pdwCookie);
this._eventSinkHelper.m_dwCookie = pdwCookie;
}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
//MessageBox.Show(errorMessage, "Error");
throw theException;
}
}
public IDrvCtx GetCtx()
{
return this._drvCtx;
}
// Use C# destructor syntax for finalization code.
// This destructor will run only if the Dispose method
// does not get called.
// It gives your base class the opportunity to finalize.
// Do not provide destructors in types derived from this class.
~DrvCtxWrap()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
// Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// This object will be cleaned up by the Dispose method.
// Therefore, you should call GC.SupressFinalize to
// take this object off the finalization queue
// and prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
// Dispose(bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly
// or indirectly by a user's code. Managed and unmanaged resources
// can be disposed.
// If disposing equals false, the method has been called by the
// runtime from inside the finalizer and you should not reference
// other objects. Only unmanaged resources can be disposed.
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
this._connectionPointContainer = null;
}
// Call the appropriate methods to clean up
// unmanaged resources here.
// If disposing is false,
// only the following code is executed.
try
{
if (this._connectionPoint != null)
{
this._connectionPoint.Unadvise(this._eventSinkHelper.m_dwCookie);
Marshal.ReleaseComObject(this._connectionPoint);
this._connectionPoint = null;
this._eventSinkHelper = null;
}
if (this._drvCtx != null)
{
Marshal.ReleaseComObject(this._drvCtx);
this._drvCtx = null;
}
}
catch (Exception)
{
}
finally
{
}
}
disposed = true;
}
}
}