/* the resultant list is a double NULL terminated list of NULL terminated strings. */
STATIC EFI_STATUS CopyListOfCommandNamesWithDynamic(IN OUT CHAR16 **DestList, IN OUT UINTN *DestSize)
/* the resultant list is a double NULL terminated list of NULL terminated strings. */
STATIC EFI_STATUS CopyListOfCommandNamesWithDynamic(IN OUT CHAR16 **DestList, IN OUT UINTN *DestSize)
{
  EFI_HANDLE                          *CommandHandleList;
  CONST EFI_HANDLE                    *NextCommand;
  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;
  EFI_STATUS                          Status;
  CommandHandleList = GetHandleListByProtocol (&gEfiShellDynamicCommandProtocolGuid);
  if (CommandHandleList == NULL) {
    return (EFI_SUCCESS);
  }
  Status = EFI_SUCCESS;
  for (NextCommand = CommandHandleList; *NextCommand != NULL && !EFI_ERROR (Status); NextCommand++) {
    Status = gBS->HandleProtocol (
                    *NextCommand,
                    &gEfiShellDynamicCommandProtocolGuid,
                    (VOID **)&DynamicCommand
                    );
    if (EFI_ERROR (Status)) {
      continue;
    }
    Status = LexicalInsertIntoList (DestList, DestSize, DynamicCommand->CommandName);
  }
  SHELL_FREE_NON_NULL (CommandHandleList);
  return (Status);
}