/* If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. */
EFI_STATUS EFIAPI InternalHiiExtractGuidFromHiiHandle(IN EFI_HII_HANDLE Handle, OUT EFI_GUID *Guid)
/* If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. */
EFI_STATUS EFIAPI InternalHiiExtractGuidFromHiiHandle(IN EFI_HII_HANDLE Handle, OUT EFI_GUID *Guid)
{
  EFI_STATUS                   Status;
  UINTN                        BufferSize;
  EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;
  ASSERT (Guid != NULL);
  ASSERT (Handle != NULL);
  BufferSize     = 0;
  HiiPackageList = NULL;
  Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
  ASSERT (Status != EFI_NOT_FOUND);
  if (Status == EFI_BUFFER_TOO_SMALL) {
    HiiPackageList = AllocatePool (BufferSize);
    ASSERT (HiiPackageList != NULL);
    Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
  }
  if (EFI_ERROR (Status)) {
    FreePool (HiiPackageList);
    return Status;
  }
  CopyGuid (Guid, &HiiPackageList->PackageListGuid);
  FreePool (HiiPackageList);
  return EFI_SUCCESS;
}