public System.IntPtr MarshalManagedToNative(object ManagedObj) { SecurityAttributes saIn = (SecurityAttributes)ManagedObj; if (saIn == null) return IntPtr.Zero; // Keep a reference to the wrapper in case "MarshalNativeToManaged" // is called later (In/Out marshaling) this._wrapper = saIn; // Allocate unmanaged memeory to store the SECURITY_ATTRIBUTES struct SECURITY_ATTRIBUTES saOut = saIn.GetSECURITY_ATTRIBUTES(); IntPtr pSaIn = Win32.AllocGlobal(SECURITY_ATTRIBUTES.SizeOf); Marshal.StructureToPtr(saOut, pSaIn, false); return pSaIn; }
public object MarshalNativeToManaged(System.IntPtr pNativeData) { // If native ptr is NULL, return null if (pNativeData == IntPtr.Zero) return null; // If we have an existing wrapper, re-use it. // This allows us to properly support the In/Out semantics. if (_wrapper != null) { _wrapper.Parse(pNativeData); return _wrapper; } // Create a new wrapper and parse the native struct _wrapper = new SecurityAttributes(); _wrapper.Parse(pNativeData); return _wrapper; }