From 2b4cfee7e23dd2c2cbb30b2c1e1961cfd7dbfcc8 Mon Sep 17 00:00:00 2001 From: dahall Date: Mon, 25 Jan 2021 12:10:13 -0700 Subject: [PATCH] Added SafeMemStruct.InitializeSizeField method to initialize an in-memory structure's size field --- Core/InteropServices/SafeMemStruct.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/InteropServices/SafeMemStruct.cs b/Core/InteropServices/SafeMemStruct.cs index 50e280f7..f6c55773 100644 --- a/Core/InteropServices/SafeMemStruct.cs +++ b/Core/InteropServices/SafeMemStruct.cs @@ -153,6 +153,10 @@ namespace Vanara.InteropServices /// public virtual TStruct GetValueOrDefault(in TStruct defaultValue = default) => HasValue ? Value : defaultValue; + /// Initializes the size field by the specified name or the first four bytes of the structure's memory. + /// Name of the field. + public virtual void InitializeSizeField(string fieldName = null) => (fieldName is null ? handle : GetFieldAddress(fieldName)).Write((uint)BaseStructSize); + /// Returns the string value held by this instance. /// A value held by this instance or null if the handle is invalid. public override string ToString() => ((TStruct?)this).ToString();