Create and initialize a new DATE_LOG_HANDLE for date collection management
InitializeDateLogHandle creates and initializes a new DATE_LOG_HANDLE for managing date collections with support for three distinct handle types: DateLog, DateRange, and Holidays. The function establishes a thread-safe, shared context with mutex-based synchronization and reference counting to enable concurrent access from multiple threads.
This is the primary entry point for creating date collection handles. It allocates necessary structures, initializes synchronization primitives, and establishes the foundation for all date operations within the MDTS library.
HRESULT _Must_inspect_result_ _Success_(SUCCEEDED(return)) InitializeDateLogHandle(
_In_opt_ PSECURITY_ATTRIBUTES pSecAttr,
_In_opt_ _Pre_satisfies_(dwMaximumLength <= DATE_LOG_MAX) const DWORD dwMaximumLength,
_In_opt_ _When_(HandleType == HandleIsForDatelog, _Notnull_ _Valid_) HOLIDAYS_HANDLE hHolidays,
_Out_ DATE_LOG_HANDLE *hDateLogHandle,
_In_ DateHandleType HandleType
);
Standard C calling convention with SAL annotations for parameter validation and return value inspection.
[In, Optional] PSECURITY_ATTRIBUTES
Security attributes for the mutexes created by this function. Can be NULL to use default security.
[In, Optional] DWORD
Maximum number of date items this collection can hold. Determines pre-allocated capacity.
DATE_LOG_MAX (368,072 items)DATE_LOG_MAX if not specifiedMAX_HOLIDAYS (341 items) if not specified[In, Optional] HOLIDAYS_HANDLE
Handle to holidays collection for market day validation. Required for DateLog and DateRange types.
[Out] DATE_LOG_HANDLE*
Pointer to receive the newly created DATE_LOG_HANDLE on success.
FreeDateCollectionHandle() when no longer needed[In] DateHandleType
Specifies the type of collection handle to create. Determines behavior and requirements.
| Handle Type | Purpose | hHolidays Required | Max Size |
|---|---|---|---|
HandleIsForDatelog |
Full date log with all market dates | Yes (non-NULL) | DATE_LOG_MAX |
HandleIsForRange |
Temporary date range for merge operations | Yes (non-NULL) | DATE_LOG_MAX |
HandleIsForHolidays |
Collection of holiday and weekend dates | No (must be NULL) | MAX_HOLIDAYS |
Handle created successfully. hDateLogHandle contains valid pointer to new handle.
Invalid parameter provided:
dwMaximumLength exceeds DATE_LOG_MAXHandleType is not a valid DateHandleType valuehDateLogHandle is NULLhHolidays is NULLhHolidays is not NULLhHolidays handle is invalid or corrupted. Handle must be previously created by InitializeDateLogHandle.
Insufficient memory to allocate handle structures, context, or mutexes. Check available system memory.
System error from mutex creation or security validation. Wrapped as HRESULT.
The function allocates the following structures:
Three levels of synchronization are established:
// First, create holidays handle
HOLIDAYS_HANDLE hHolidays = NULL;
HRESULT hr = InitializeDateLogHandle(
NULL, // Default security
0, // Default size (MAX_HOLIDAYS)
NULL, // No parent holidays needed
&hHolidays,
HandleIsForHolidays
);
if (SUCCEEDED(hr)) {
// Now create DateLog handle
DATE_LOG_HANDLE hDateLog = NULL;
hr = InitializeDateLogHandle(
NULL, // Default security
100000, // Max 100,000 dates
hHolidays, // Holidays for validation
&hDateLog,
HandleIsForDatelog
);
if (SUCCEEDED(hr)) {
printf("DateLog handle created successfully\n");
FreeDateCollectionHandle(hDateLog);
}
FreeDateCollectionHandle(hHolidays);
}
// Create a temporary date range for merging
DATE_RANGE_HANDLE hDateRange = NULL;
HRESULT hr = InitializeDateLogHandle(
NULL, // Default security
10000, // Max 10,000 items for range
hHolidays, // Holidays handle
&hDateRange,
HandleIsForRange
);
if (SUCCEEDED(hr)) {
printf("DateRange created successfully\n");
FreeDateCollectionHandle(hDateRange);
}
DATE_LOG_HANDLE hDateLog = NULL;
HRESULT hr = InitializeDateLogHandle(
NULL, // pSecAttr
500000, // dwMaximumLength - EXCEEDS LIMIT!
hHolidays,
&hDateLog,
HandleIsForDatelog
);
if (hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)) {
printf("Maximum length exceeds DATE_LOG_MAX\n");
// Use default size instead
hr = InitializeDateLogHandle(
NULL,
0, // Use default
hHolidays,
&hDateLog,
HandleIsForDatelog
);
}
The context uses reference counting to manage lifetime:
DuplicateDateLogHandle()FreeDateCollectionHandle()FreeDateCollectionHandle()
to properly decrement reference counts and release resources.
dwMaximumLength parameter must not exceed DATE_LOG_MAX.
SECURITY_ATTRIBUTES
structure. Default NULL uses process security context.
FreeDateCollectionHandle() - Release handle and decrement reference countDuplicateDateLogHandle() - Create additional reference to same contextLoadDateLogHandle() - Populate handle with dates from file or rangeMergeDateLogHandle() - Merge two handles together