// C/C++
#include <shlobj.h>

LPITEMIDLIST GetNextItemID(const LPITEMIDLIST pidl)
{
  size_t cb = pidl->mkid.cb;
  if( cb == 0 )
  {
    return NULL;
  }
  pidl = (LPITEMIDLIST) (((LPBYTE) pidl) + cb);
  if( pidl->mkid.cb == 0 )
  {
    return NULL;
  }
  return pidl;
}
// Delphi
uses ShlObj;

type
  PByte = ^Byte;

function GetNextItemID(pidl: PItemIDList): PItemIDList;
var
  cb: Integer;
begin
  cb := pidl^.mkid.cb;
  if cb = 0 then
  begin
    Result := nil;
    Exit;
  end;
  pidl := PItemIDList ( Integer(PByte(pidl)) + cb );
  if pidl^.mkid.cb = 0 then
  begin
    Result := nil;
    Exit;
  end;
  Result := pidl;
end;