Skip to content

NativeStaticContainer

ShadowKnightMK4 edited this page Apr 21, 2022 · 4 revisions

public abstract class NativeStaticContainer : IDisposable


This abstract class Implements holding a pointer to either a Native C++ class or block of memory that can potentially be freed() either via C/c++'s free() or has a dedicated C level wrapper that destroys the class. A lot of classes in the sheath are subclassed from this, and itself implements IDispoable.

protected string ConstructReceivedNullPointerOnConstructor_message(string ArgumentPrefix, string AlternativeInstance, string ArgumentName);

This is a routine that takes a few strings and returns a canned message pointing the user to use the AlternativeInstance instance of a constructor.

protected virtual void Dispose(bool disposing);

NativeStaticContainer's Dispose calls C/C++'s free() by default if the class was created with FreeOnCleanup set to true. You're going to want to overwrite this behavior if your wrapper for the native class requires a different cleanup routine. For Example, look at how InsightProcess/ PsProcessInformation's dispose() is implemented in the source.

public void Dispose();

This is required for IDisposable. This calls the protected Dispose() chain.

public override bool Equals(object obj);

Equals() has been overwritten to compare if each object has the Same Native IntPtr or not.

public override int GetHashCode();

GetHashCode() been overwritten to return a hash of the Native IntPtr;

public NativeStaticContainer(IntPtr Native);

This instances the class to point to the native class as specified by your argument. FreeOnCleanup is set to true.

public NativeStaticContainer(IntPtr Native, bool FreeOnCleanup);

This instances the class to point to the native class as specified by your argument. If FreeOnCleanup is true, C/C++'s free() will be called on the native side. It is Recommended that one has some knowledge of how the native class is instanced otherwise you may get some memory leaks.

public bool IsDisposed;

This provides functionally readonly access is disposedValue to test if a NativeStaticClass's dispose() routine has been called.

public IntPtr NativePointer;

This provides a functional readonly access to the protected pointer. You will be making a mistake if you prematurely call the deconstructor for the underlying class / data structure in the native side.

protected bool disposedValue;

This holds the value that IsDiposed returns.

protected bool FreeOnCleanup{get;}

This provides readonly access to the protected FreeOnCleanup container.

protected bool FreeOnCleanupContainer;

This holds the value that FreeOnCleanup returns.

protected readonly IntPtr Native;

This holds the Pointer to the native class or struct this C# class is containing.

~NativeStaticContainer();

Finalizer. Functionally calls the protected dispose Dispose(false)