From: Mathieu M. <mat...@gm...> - 2009-05-05 16:29:26
|
'lo, [Sorry for the empty email earlier in the day] I am trying to wrap a C++ object which use the following pattern (factory design pattern if I am not mistaken). It goes like this: struct Foo { static Foo* New() { return new Foo; } virtual void Delete(); // call reference counting mechanism protected: Foo(); ~Foo(); }; So in order to get the reference counting mechanism to work properly I need to call Foo::New() in the cstor and Foo::Delete in the destrutor. for the cstor this was easy: %extend Foo { %typemap(cscode) Foo %{ public Foo() : this(vtkgdcmswigPINVOKE.Foo_New(), true) {} %} }; But I do not understand what I need to do to get 'Dispose' to call Delete on the C++ object. Right now I have: public virtual void Dispose() { lock(this) { if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) { swigCMemOwn = false; throw new MethodAccessException("C++ destructor does not have public access"); } swigCPtr = new HandleRef(null, IntPtr.Zero); GC.SuppressFinalize(this); } } Thanks for suggestion, -- Mathieu |