Find a date item in a date collection using various search criteria
FindDateItemHandle is a dispatcher function that searches for a date item within a date collection using one of four supported search criteria. It provides a unified interface for flexible date item lookup operations with automatic synchronization and handle validation.
This function enables applications to locate specific date items within a date log collection using different search strategies:
DATE_ITEM_HANDLE _Check_return_ _Success_(return != NULL) FindDateItemHandle(
_In_ _Pre_valid_ DATE_COLLECTION_HANDLE hDateCollection,
_In_opt_ _When_(pFiletime == NULL && pLargeInt == NULL && rfDateId == NULL, _Notnull_)
DATE_ITEM_HANDLE hDateItem,
_In_opt_ _When_(hDateItem == NULL && pLargeInt == NULL && rfDateId == NULL, _Notnull_)
PFILETIME pFiletime,
_In_opt_ _When_(hDateItem == NULL && pFiletime == NULL && rfDateId == NULL, _Notnull_)
PLARGE_INTEGER pLargeInt,
_In_opt_ _When_(hDateItem == NULL && pFiletime == NULL && pLargeInt == NULL, _Notnull_)
GUID * rfDateId
);
Standard C calling convention with SAL annotations enforcing exclusive search criteria.
[In] DATE_COLLECTION_HANDLE
Handle to the date collection to search.
NewDateLogHandle() or ConvertToDateLogHandle()IsValidDateLogHandle()[In, Optional] DATE_ITEM_HANDLE
Handle to the date item to find.
SearchDateItem() internal helper[In, Optional] PFILETIME
Pointer to FILETIME value to search for.
SearchDateItemByFileTime() with O(log n) performance[In, Optional] PLARGE_INTEGER
Pointer to LARGE_INTEGER value to search for.
SearchDateItemByLargeInteger() with O(log n) performance[In, Optional] GUID *
Pointer to GUID (unique identifier) to search for.
SearchDateItemByGuid() with O(n) performanceA valid handle to the found date item. This handle can be used with other date-item functions for further operations.
Returned when:
IsValidDateLogHandle() check)Returned when the search criteria does not match any date item in the collection:
Returned if the underlying search helper fails to acquire necessary mutexes within the 30-second timeout. This may indicate system resource contention or other operations holding locks.
// Simple usage pattern
DATE_ITEM_HANDLE hFound = FindDateItemHandle(
hDateCollection,
hSearchItem, // Search by handle
NULL, // Not searching by FILETIME
NULL, // Not searching by LARGE_INTEGER
NULL // Not searching by GUID
);
if (hFound != NULL) {
// Item found, can now use hFound with other functions
printf("Found date item\n");
} else {
// Item not found or validation error
printf("Date item not found or error occurred\n");
}
Before dispatching to the appropriate search helper, the function performs three validation checks:
IsValidDateLogHandle(hDateCollection)
pDateLog->pContext is not NULLpContext->hDateLogCore is not NULLAfter validation, the function dispatches to the appropriate search helper based on the first non-NULL criterion in this priority order:
hDateItem != NULL: Call SearchDateItem(hDateLogCore, hDateItem)pFiletime != NULL: Call SearchDateItemByFileTime(hDateLogCore, pFiletime)pLargeInt != NULL: Call SearchDateItemByLargeInteger(hDateLogCore, pLargeInt)rfDateId != NULL: Call SearchDateItemByGuid(hDateLogCore, rfDateId)All underlying search helpers are protected by mutexes:
Search by providing another DATE_ITEM_HANDLE:
DATE_ITEM_HANDLE hItemToFind = /* obtained from previous operation */;
DATE_ITEM_HANDLE hResult = FindDateItemHandle(
hDateCollection,
hItemToFind, // Search for this handle
NULL, // Ignore FILETIME
NULL, // Ignore LARGE_INTEGER
NULL // Ignore GUID
);
Search by providing a FILETIME value (Windows 64-bit file time):
FILETIME ftSearchDate;
// Initialize ftSearchDate with target date
GetSystemTimeAsFileTime(&ftSearchDate);
DATE_ITEM_HANDLE hResult = FindDateItemHandle(
hDateCollection,
NULL, // Ignore handle search
&ftSearchDate, // Search for this FILETIME
NULL, // Ignore LARGE_INTEGER
NULL // Ignore GUID
);
Search by providing a LARGE_INTEGER value:
LARGE_INTEGER liSearchValue;
liSearchValue.QuadPart = 132500000000000000LL; // Custom date representation
DATE_ITEM_HANDLE hResult = FindDateItemHandle(
hDateCollection,
NULL, // Ignore handle search
NULL, // Ignore FILETIME
&liSearchValue, // Search for this LARGE_INTEGER
NULL // Ignore GUID
);
Search by providing a GUID (unique identifier):
GUID guidSearchValue = {0x12345678, 0x1234, 0x1234, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}};
DATE_ITEM_HANDLE hResult = FindDateItemHandle(
hDateCollection,
NULL, // Ignore handle search
NULL, // Ignore FILETIME
NULL, // Ignore LARGE_INTEGER
&guidSearchValue // Search for this GUID
);
// Find today's date in the collection
SYSTEMTIME stNow;
GetLocalTime(&stNow);
FILETIME ftNow;
SystemTimeToFileTime(&stNow, &ftNow);
DATE_ITEM_HANDLE hTodayItem = FindDateItemHandle(
hMyDateCollection,
NULL,
&ftNow,
NULL,
NULL
);
if (hTodayItem != NULL) {
printf("Found today's date in collection\n");
} else {
printf("Today's date not found in collection\n");
}
// Search for item by GUID
GUID targetGuid = /* obtained from data source */;
DATE_ITEM_HANDLE hFoundItem = FindDateItemHandle(
hMyDateCollection,
NULL,
NULL,
NULL,
&targetGuid
);
switch (hFoundItem == NULL) {
case TRUE:
printf("Item with GUID not found in collection\n");
break;
case FALSE:
printf("Found item, handle = %p\n", hFoundItem);
// Use hFoundItem for further operations
break;
}
// Perform multiple searches for different criteria
FILETIME ftSearch1, ftSearch2, ftSearch3;
// Initialize search dates...
// First search
DATE_ITEM_HANDLE h1 = FindDateItemHandle(hCollection, NULL, &ftSearch1, NULL, NULL);
// Second search
DATE_ITEM_HANDLE h2 = FindDateItemHandle(hCollection, NULL, &ftSearch2, NULL, NULL);
// Third search
DATE_ITEM_HANDLE h3 = FindDateItemHandle(hCollection, NULL, &ftSearch3, NULL, NULL);
// Verify results
if (h1 != NULL && h2 != NULL && h3 != NULL) {
printf("All three items found\n");
}
The function uses exclusive SAL annotations to enforce that exactly one search criterion is provided:
_Check_return_ - Caller must check the return value_Success_(return != NULL) - Function succeeds when returning non-NULL_When_ clauses - Enforce mutual exclusivity of search parameters_Notnull_ - The appropriate criterion must be non-NULL| Search Type | Time Complexity | Best For |
|---|---|---|
| Handle | O(n) or O(1) | Verifying existing handles |
| FILETIME | O(log n) | Calendar date lookups |
| LARGE_INTEGER | O(log n) | Custom date representations |
| GUID | O(n) | Unique identifier lookups |
SearchDateItem() - Low-level handle-based search helperSearchDateItemByFileTime() - Low-level FILETIME search with binary searchSearchDateItemByLargeInteger() - Low-level LARGE_INTEGER searchSearchDateItemByGuid() - Low-level GUID search helperIsValidDateLogHandle() - Validate collection handleGetDateItemPrevious() - Navigate to previous itemGetDateItemNext() - Navigate to next itemFindDateItemHandle() concurrently on the same collection. Each search
operation acquires necessary mutexes atomically and releases them before returning.
// Pattern 1: Check before using
if (FindDateItemHandle(hColl, hItem, NULL, NULL, NULL) != NULL) {
// Item exists, safe to use hItem
}
// Pattern 2: Store result for further operations
DATE_ITEM_HANDLE hFound = FindDateItemHandle(hColl, NULL, &ft, NULL, NULL);
if (hFound != NULL) {
// Use hFound with other functions
}
// Pattern 3: Search with multiple criteria (try each in order)
DATE_ITEM_HANDLE hResult = FindDateItemHandle(hColl, hItem, NULL, NULL, NULL);
if (hResult == NULL && pFiletime != NULL) {
hResult = FindDateItemHandle(hColl, NULL, pFiletime, NULL, NULL);
}