question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shell32 - Fetching multiple Item with IEnumIDList.Next()

See original GitHub issue

Not really a problem but rather a question (I guess?) Regarding the IEnumIDList interface and his .Next() method.

Usually I use it like this :

while (enumIdList.Next(1, out IntPtr pIdlOut, out _) == HRESULT.S_OK) // S_OK and not .Successed
{
// do something
}

The problem is that if I want to fetch more than 1 item pIdlOut must be an array (IntPtr[]), right ? I can’t do :

if (enumIdList.Next(5, out IntPtr pIdlOut, out _) == HRESULT.S_OK)
{
// pIdlOut is the last feteched pidl
// fetching more than 5 items throw an error (System.ExecutionEngineException)
}

Changing the .Next() Method to

HRESULT Next(uint celt, [MarshalAs(UnmanagedType.LPArray), Out] out IntPtr[] rgelt, out uint pceltFetched);

or

HRESULT Next(uint celt, [MarshalAs(UnmanagedType.LPArray), In] in IntPtr[] rgelt, out uint pceltFetched);

Same issue.

From MSDN :

rgelt Type: LPITEMIDLIST* The address of a pointer to an array of ITEMIDLIST pointers

The implementation must allocate these item identifiers using CoTaskMemAlloc

I guess I need to pass an already allocated array, but how ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
dahallcommented, Jan 8, 2020
foreach (var pidl in enumIdList.Enumerate(fv.ItemCount(SVGIO.SVGIO_ALLVIEW)))
{
    using (pidl)
    {
        // Do something with pidl;
    }
}
1reaction
dahallcommented, Jan 4, 2020

I just changed the definition in Vanara.PInvoke.Shell32 to the one I thought was the correct definition and tested it. It now works as it should. I also added an extension method for IEnumIDList instances called Enumerate that will take a parameter to determine retrieval size. The default value for that parameter is set to 1. It can be used like:

// Enumerate all PIDLs in enumIdList requesting 20 at a time
IEnumerable<PIDL> pidls = enumIdList.Enumerate(20);

// Enumerate all PIDLs in enumIdList requesting 1 at a time
IEnumerable<PIDL> pidls2 = enumIdList.Enumerate();
Read more comments on GitHub >

github_iconTop Results From Across the Web

IEnumIDList::Next (shobjidl_core.h) - Win32 apps
Retrieves the specified number of item identifiers in the enumeration sequence and advances the current position by the number of items ...
Read more >
Wine Announcement - The Wine development release 2.18 ...
Andrew Eikum (2): wineandroid: Create OpenSL outputmix object globally. ... API. shell32: Fix IEnumIDList::Next() called for multiple items. shell32: ...
Read more >
C# get thumbnail from file via windows api
The MSDN code works with hidden files, whereas, the vbAccelerator code needs then SHCONTF_INCLUDEHIDDEN added to the EnumObjects call. In ...
Read more >
IEnumIDList - COM Discussion Boards
I am converting COM stuff to C#, but i'm not entirely sure about IEnumIDList.Next, or what exactly it returns. HRESULT Next( ULONG celt,...
Read more >
ObjCreateInterface example: Enumerating and Browsing ...
The default sorting is the order of files and folders as provided in the "While $IEnumIDList.Next() ... WEnd" loops. Virtual folders.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found