本文整理汇总了C#中NativeMethods.EnumElements方法的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods.EnumElements方法的具体用法?C# NativeMethods.EnumElements怎么用?C# NativeMethods.EnumElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeMethods
的用法示例。
在下文中一共展示了NativeMethods.EnumElements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadStorage
/// <summary>
/// Processes sub streams and storages on the specified storage.
/// </summary>
/// <param name="storage"> The storage to get sub streams and storages for. </param>
protected virtual void LoadStorage(NativeMethods.IStorage storage)
{
if (storage == null)
throw new ArgumentNullException("storage", "Storage can not be null");
_storage = storage;
// Ensures memory is released
ReferenceManager.AddItem(storage);
NativeMethods.IEnumSTATSTG storageElementEnum = null;
try
{
// Enum all elements of the storage
storage.EnumElements(0, IntPtr.Zero, 0, out storageElementEnum);
// Iterate elements
while (true)
{
// Get 1 element out of the COM enumerator
uint elementStatCount;
var elementStats = new STATSTG[1];
storageElementEnum.Next(1, elementStats, out elementStatCount);
// Break loop if element not retrieved
if (elementStatCount != 1)
break;
var elementStat = elementStats[0];
switch (elementStat.type)
{
case 1:
// Element is a storage, add its statistics object to the storage dictionary
_subStorageStatistics.Add(elementStat.pwcsName, elementStat);
break;
case 2:
// Element is a stream, add its statistics object to the stream dictionary
_streamStatistics.Add(elementStat.pwcsName, elementStat);
break;
}
}
}
finally
{
// Free memory
if (storageElementEnum != null)
Marshal.ReleaseComObject(storageElementEnum);
}
}