回答編集履歴
1
C#のコードを追加しました
answer
CHANGED
@@ -160,4 +160,158 @@
|
|
160
160
|
}
|
161
161
|
```
|
162
162
|
|
163
|
-
あとは「共通言語ランタイム サポート (/clr)」「ダイナミック ライブラリ (.dll)」の設定への変更とスタティックライブラリへのパスを設定してビルドすればC#からでもVB/F#からでもこのcounterクラスを呼び出すことができます
|
163
|
+
あとは「共通言語ランタイム サポート (/clr)」「ダイナミック ライブラリ (.dll)」の設定への変更とスタティックライブラリへのパスを設定してビルドすればC#からでもVB/F#からでもこのcounterクラスを呼び出すことができます。
|
164
|
+
|
165
|
+
ILSpyというツールを使ってCounterを解析すると以下のようなC#のコードが生成されています。
|
166
|
+
```cs
|
167
|
+
using System;
|
168
|
+
using System.Runtime.ExceptionServices;
|
169
|
+
using System.Runtime.InteropServices;
|
170
|
+
|
171
|
+
namespace CounterLib
|
172
|
+
{
|
173
|
+
public class Counter : ICppInstance, IDisposable
|
174
|
+
{
|
175
|
+
private unsafe counter* <backing_store>NativePtr;
|
176
|
+
|
177
|
+
protected bool __ownsNativeInstance;
|
178
|
+
|
179
|
+
public int Value
|
180
|
+
{
|
181
|
+
get
|
182
|
+
{
|
183
|
+
return <Module>.counter.value(this.<backing_store>NativePtr);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
public unsafe virtual IntPtr __Instance
|
188
|
+
{
|
189
|
+
get
|
190
|
+
{
|
191
|
+
IntPtr result = new IntPtr((void*)this.<backing_store>NativePtr);
|
192
|
+
return result;
|
193
|
+
}
|
194
|
+
set
|
195
|
+
{
|
196
|
+
this.<backing_store>NativePtr = (counter*)value.ToPointer();
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
public unsafe counter* NativePtr
|
201
|
+
{
|
202
|
+
get
|
203
|
+
{
|
204
|
+
return this.<backing_store>NativePtr;
|
205
|
+
}
|
206
|
+
set
|
207
|
+
{
|
208
|
+
this.<backing_store>NativePtr = value;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
public unsafe Counter(Counter _0)
|
213
|
+
{
|
214
|
+
this.__ownsNativeInstance = true;
|
215
|
+
if (object.ReferenceEquals(_0, null))
|
216
|
+
{
|
217
|
+
throw new ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
|
218
|
+
}
|
219
|
+
counter* ptr = _0.<backing_store>NativePtr;
|
220
|
+
counter* ptr2 = <Module>.@new(4u);
|
221
|
+
counter* ptr3;
|
222
|
+
if (ptr2 != null)
|
223
|
+
{
|
224
|
+
cpblk(ptr2, ptr, 4);
|
225
|
+
ptr3 = ptr2;
|
226
|
+
}
|
227
|
+
else
|
228
|
+
{
|
229
|
+
ptr3 = null;
|
230
|
+
}
|
231
|
+
this.<backing_store>NativePtr = ptr3;
|
232
|
+
}
|
233
|
+
|
234
|
+
public unsafe Counter()
|
235
|
+
{
|
236
|
+
this.__ownsNativeInstance = true;
|
237
|
+
counter* ptr = <Module>.@new(4u);
|
238
|
+
counter* ptr2;
|
239
|
+
try
|
240
|
+
{
|
241
|
+
if (ptr != null)
|
242
|
+
{
|
243
|
+
ptr2 = <Module>.counter.{ctor}(ptr);
|
244
|
+
}
|
245
|
+
else
|
246
|
+
{
|
247
|
+
ptr2 = 0;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
catch
|
251
|
+
{
|
252
|
+
<Module>.delete((void*)ptr, 4u);
|
253
|
+
throw;
|
254
|
+
}
|
255
|
+
this.<backing_store>NativePtr = ptr2;
|
256
|
+
}
|
257
|
+
|
258
|
+
public unsafe Counter(counter* native)
|
259
|
+
{
|
260
|
+
this.__ownsNativeInstance = false;
|
261
|
+
base..ctor();
|
262
|
+
this.<backing_store>NativePtr = native;
|
263
|
+
}
|
264
|
+
|
265
|
+
public unsafe static Counter __CreateInstance(IntPtr native)
|
266
|
+
{
|
267
|
+
return new Counter((counter*)native.ToPointer());
|
268
|
+
}
|
269
|
+
|
270
|
+
private unsafe void ~Counter()
|
271
|
+
{
|
272
|
+
<Module>.delete((void*)this.<backing_store>NativePtr, 4u);
|
273
|
+
}
|
274
|
+
|
275
|
+
private unsafe void !Counter()
|
276
|
+
{
|
277
|
+
<Module>.delete((void*)this.<backing_store>NativePtr, 4u);
|
278
|
+
}
|
279
|
+
|
280
|
+
public void Increment()
|
281
|
+
{
|
282
|
+
<Module>.counter.increment(this.<backing_store>NativePtr);
|
283
|
+
}
|
284
|
+
|
285
|
+
[HandleProcessCorruptedStateExceptions]
|
286
|
+
protected unsafe virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool A_0)
|
287
|
+
{
|
288
|
+
if (A_0)
|
289
|
+
{
|
290
|
+
<Module>.delete((void*)this.<backing_store>NativePtr, 4u);
|
291
|
+
}
|
292
|
+
else
|
293
|
+
{
|
294
|
+
try
|
295
|
+
{
|
296
|
+
this.!Counter();
|
297
|
+
}
|
298
|
+
finally
|
299
|
+
{
|
300
|
+
base.Finalize();
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
public sealed override void Dispose()
|
306
|
+
{
|
307
|
+
this.Dispose(true);
|
308
|
+
GC.SuppressFinalize(this);
|
309
|
+
}
|
310
|
+
|
311
|
+
protected override void Finalize()
|
312
|
+
{
|
313
|
+
this.Dispose(false);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
}
|
317
|
+
```
|