namespace Vanara.PInvoke; public static partial class ClfsW32 { /// /// The LOG_FULL_HANDLER_CALLBACK function is an application-defined callback function that receives notification that the call to /// HandleLogFull is complete. The callback is invoked in the context of an asynchronous procedure call (APC) on the thread that /// registered for log management. /// /// The handle to the log. /// The status of the operation. /// /// Specifies if the log is considered "pinned". If fLogIsPinned is TRUE and the log is then unpinned, the /// LOG_UNPINNED_CALLBACK is invoked. /// /// A pointer to the client context. /// The client application determines which actions this callback function performs. // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nc-clfsmgmtw32-plog_full_handler_callback PLOG_FULL_HANDLER_CALLBACK // PlogFullHandlerCallback; void PlogFullHandlerCallback( [in] HLOG hLogFile, [in] DWORD dwError, [in] BOOL fLogIsPinned, [in] PVOID // pvClientContext ) {...} [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NC:clfsmgmtw32.PLOG_FULL_HANDLER_CALLBACK")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PLOG_FULL_HANDLER_CALLBACK([In] HLOG hLogFile, [In] Win32Error dwError, [MarshalAs(UnmanagedType.Bool)] bool fLogIsPinned, [In] IntPtr pvClientContext); /// /// The LOG_TAIL_ADVANCE_CALLBACK function is an application-defined callback function that advances the log tail. The callback is /// invoked in the context of an asynchronous procedure call (APC) on the thread that registers for log management. /// /// The handle to the log. /// /// Specifies the log sequence number (LSN) to which the client is advised to advance to or beyond. The lsnTarget may not refer to /// an actual record in the log. /// /// A pointer to the client context. /// None /// /// This callback can be invoked at any time. This callback function should advance the base LSN of the log to greater than or equal to /// the value of lsnTarget. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nc-clfsmgmtw32-plog_tail_advance_callback PLOG_TAIL_ADVANCE_CALLBACK // PlogTailAdvanceCallback; void PlogTailAdvanceCallback( [in] HLOG hLogFile, [in] CLFS_LSN lsnTarget, [in] PVOID pvClientContext ) {...} [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NC:clfsmgmtw32.PLOG_TAIL_ADVANCE_CALLBACK")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PLOG_TAIL_ADVANCE_CALLBACK([In] HLOG hLogFile, [In] CLS_LSN lsnTarget, [In] IntPtr pvClientContext); /// /// The LOG_UNPINNED_CALLBACK function is an application-defined callback function that receives notification that the log has /// become unpinned. The callback is invoked in the context of an asynchronous procedure call (APC) on the thread that registers for log management. /// /// The handle to the log. /// /// A pointer to the client context. This is the same context specified when registering the client, which is a member of LOG_MANAGEMENT_CALLBACKS. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nc-clfsmgmtw32-plog_unpinned_callback PLOG_UNPINNED_CALLBACK // PlogUnpinnedCallback; void PlogUnpinnedCallback( [in] HLOG hLogFile, [in] PVOID pvClientContext ) {...} [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NC:clfsmgmtw32.PLOG_UNPINNED_CALLBACK")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PLOG_UNPINNED_CALLBACK([In] HLOG hLogFile, [In] IntPtr pvClientContext); /// The DeregisterManageableLogClient function deregisters a client with the log manager. /// The handle to deregister. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. For extended error information, call GetLastError. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-deregistermanageablelogclient CLFSUSER_API BOOL // DeregisterManageableLogClient( [in] HLOG hLog ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.DeregisterManageableLogClient")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeregisterManageableLogClient([In] HLOG hLog); /// /// The HandleLogFull function is called by a managed log client when an attempt to reserve or append to a log fails with a log /// full error message. The log manager attempts to resolve the log full condition for the client, and notifies the client when the /// outcome is known. As a result of this call, the log may get larger in size. /// /// A handle to the log on which to resolve the log full condition. The handle must have been registered with RegisterManageableLogClient. /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Valid values include the following: /// /// /// /// If containers are created to resolve a log-full condition, they are created using the calling application's security context. /// /// HandleLogFull always results in asynchronous behavior or an error; if it returns false and GetLastError returns /// ERROR_IO_PENDING, the result is asynchronous behavior. If a request is asynchronous, a notification is sent to the client when /// the handler has either resolved the log full condition or it fails. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-handlelogfull CLFSUSER_API BOOL HandleLogFull( [in] // HLOG hLog ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.HandleLogFull")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HandleLogFull([In] HLOG hLog); /// Installs (sets) a policy for a log. /// A handle to a log. /// A pointer to a CLFS_MGMT_POLICY structure that represents the desired policy to install. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// Installing a log policy does not trigger an immediate change in behavior. /// Examples /// For an example that uses this function, see Creating a Log File. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-installlogpolicy CLFSUSER_API BOOL InstallLogPolicy( // [in] HLOG hLog, [in] PCLFS_MGMT_POLICY pPolicy ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.InstallLogPolicy")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InstallLogPolicy([In] HLOG hLog, in CLFS_MGMT_POLICY pPolicy); /// /// The LogTailAdvanceFailure function is called by a log client to indicate that it cannot comply with a request from log /// management to advance its tail. /// /// A handle to the log on which to resolve the log full condition. /// Win32 error code with the reason for the failure For a list of possible values, see System Error Codes. /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Valid values include the following: /// /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-logtailadvancefailure CLFSUSER_API BOOL // LogTailAdvanceFailure( [in] HLOG hLog, [in] DWORD dwReason ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.LogTailAdvanceFailure")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool LogTailAdvanceFailure([In] HLOG hLog, [In] Win32Error dwReason); /// The QueryLogPolicy function allows you to obtain a policy that is installed for the specified log. /// The handle to the log to query. /// Specifies the type of policy to query for. Policy types are enumerated in CLFS_MGMT_POLICY_TYPE. /// A pointer to a buffer to receive the returned policies. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero (0). To get extended error information, call GetLastError. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-querylogpolicy CLFSUSER_API BOOL QueryLogPolicy( [in] // HLOG hLog, [in] CLFS_MGMT_POLICY_TYPE ePolicyType, [out] PCLFS_MGMT_POLICY pPolicyBuffer, [in, out] PULONG pcbPolicyBuffer ); [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.QueryLogPolicy")] public static bool QueryLogPolicy([In] HLOG hLog, [In] CLFS_MGMT_POLICY_TYPE ePolicyType, out CLFS_MGMT_POLICY pPolicyBuffer) { uint sz = (uint)Marshal.SizeOf(typeof(CLFS_MGMT_POLICY)); return QueryLogPolicy(hLog, ePolicyType, out pPolicyBuffer, ref sz); } [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool QueryLogPolicy([In] HLOG hLog, [In] CLFS_MGMT_POLICY_TYPE ePolicyType, out CLFS_MGMT_POLICY pPolicyBuffer, ref uint pcbPolicyBuffer); /// /// The ReadLogNotification function retrieves notifications from the log manager. It retrieves a queued notification from the log /// manager immediately if a notification is available; otherwise the request remains pending until a notification is generated. /// /// The handle to the log. /// Receives the notification type, and if the type has parameters associated with it, the parameters. /// /// A pointer to an OVERLAPPED structure that is required for asynchronous operation. If asynchronous operation is not used, this /// parameter can be NULL. /// /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. The following is a possible /// error code: /// /// /// /// If the log handle is not created with the FILE_FLAG_OVERLAPPED file option, no operations can start on the log handle while /// the call to ReadLogNotification is pending. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-readlognotification CLFSUSER_API BOOL // ReadLogNotification( [in] HLOG hLog, [out] PCLFS_MGMT_NOTIFICATION pNotification, [in] LPOVERLAPPED lpOverlapped ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.ReadLogNotification")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ReadLogNotification([In] HLOG hLog, out CLFS_MGMT_NOTIFICATION pNotification, in NativeOverlapped lpOverlapped); /// /// The ReadLogNotification function retrieves notifications from the log manager. It retrieves a queued notification from the log /// manager immediately if a notification is available; otherwise the request remains pending until a notification is generated. /// /// The handle to the log. /// Receives the notification type, and if the type has parameters associated with it, the parameters. /// /// A pointer to an OVERLAPPED structure that is required for asynchronous operation. If asynchronous operation is not used, this /// parameter can be NULL. /// /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. The following is a possible /// error code: /// /// /// /// If the log handle is not created with the FILE_FLAG_OVERLAPPED file option, no operations can start on the log handle while /// the call to ReadLogNotification is pending. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-readlognotification CLFSUSER_API BOOL // ReadLogNotification( [in] HLOG hLog, [out] PCLFS_MGMT_NOTIFICATION pNotification, [in] LPOVERLAPPED lpOverlapped ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.ReadLogNotification")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ReadLogNotification([In] HLOG hLog, out CLFS_MGMT_NOTIFICATION pNotification, [In, Optional] IntPtr lpOverlapped); /// /// The RegisterForLogWriteNotification function is called by a managed log client to enable or disable log write notifications. /// /// A handle to the log on which to resolve the log full condition. /// Number of bytes to be written to the log file before the notification is sent. /// If TRUE, the notification is enabled. If FALSE, the notification is disabled. /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Valid values include the following: /// /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-registerforlogwritenotification CLFSUSER_API BOOL // RegisterForLogWriteNotification( [in] HLOG hLog, [in] ULONG cbThreshold, [in] BOOL fEnable ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.RegisterForLogWriteNotification")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RegisterForLogWriteNotification([In] HLOG hLog, [In] uint cbThreshold, [MarshalAs(UnmanagedType.Bool)] bool fEnable); /// /// The RegisterManageableLogClient function registers a client with the log manager. A client can specify whether to receive /// notifications by using callbacks, or have the notifications queued for retrieval by using ReadLogNotification. /// /// The handle to the log to register. Only one registration per unique opening of the log is allowed. /// /// Specifies the callbacks that the client is registering for. Valid callbacks are enumerated by LOG_MANAGEMENT_CALLBACKS. Specify zero /// to queue notifications instead. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// A client can deregister either by closing the log handle, or by calling DeregisterManageableLogClient. /// Examples /// For an example that uses this function, see Creating a Log File. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-registermanageablelogclient CLFSUSER_API BOOL // RegisterManageableLogClient( [in] HLOG hLog, [in] PLOG_MANAGEMENT_CALLBACKS pCallbacks ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.RegisterManageableLogClient")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RegisterManageableLogClient([In] HLOG hLog, in LOG_MANAGEMENT_CALLBACKS pCallbacks); /// Resets the specified policy to its default behavior. /// Handle to the log to reset the policy for. /// Specifies the policy to reset. Policy types are enumerated in CLFS_MGMT_POLICY_TYPE. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero (0). To get extended error information, call GetLastError. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-removelogpolicy CLFSUSER_API BOOL RemoveLogPolicy( [in] // HLOG hLog, [in] CLFS_MGMT_POLICY_TYPE ePolicyType ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.RemoveLogPolicy")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RemoveLogPolicy([In] HLOG hLog, [In] CLFS_MGMT_POLICY_TYPE ePolicyType); /// Adds or deletes containers from a log based on the state of the installed policies. /// A handle to a log. /// /// /// A pointer to a value that specifies the requested log size, expressed as one of the following values. For the actual resultant size, /// refer to the pResultingSize parameter. /// /// /// /// Value /// Meaning /// /// /// 0 /// /// Enforce the minimum size policy. If a minimum size policy is not installed, one of the following occurs: If a minimum size policy is /// installed, one of the following occurs: For more information, see InstallLogPolicy. /// /// /// /// 1 /// Not a valid value; the function call fails with ERROR_INVALID_PARAMETER. /// /// /// 2–1023 /// /// The desired size of the log, expressed as the number of containers. If this number is smaller than the minimum number of containers /// specified by the installed policy, the function call fails with ERROR_COULD_NOT_RESIZE_LOG. If this number is larger than the /// maximum number of containers specified by the installed policy, the log expands only as far as the policy-specified maximum number of /// containers, and the function succeeds with no error. /// /// /// /// 1024–MAXULONGLONG /// /// If no maximum size policy is installed, the function call fails with ERROR_LOG_POLICY_CONFLICT. If a maximum size policy is /// installed, the log expands to the maximum number of containers specified by the maximum size policy and the function succeeds with no error. /// /// /// /// /// /// A pointer to a valid ULONGLONG data variable, receives the number of containers in the resized log upon success. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call the GetLastError function. /// /// /// /// Containers are created using the same security attributes as the .blf file and are created within the context of the application, not /// the context of the owner of the .blf file. For more information about .blf files, see Log Types. If containers are deleted, they are /// deleted using the security context of the calling application. /// /// Examples /// For an example that uses this function, see Creating a Log File. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/nf-clfsmgmtw32-setlogfilesizewithpolicy CLFSUSER_API BOOL // SetLogFileSizeWithPolicy( [in] HLOG hLog, [in] PULONGLONG pDesiredSize, [out] PULONGLONG pResultingSize ); [DllImport(Lib_Clfsw32, SetLastError = true, ExactSpelling = true)] [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NF:clfsmgmtw32.SetLogFileSizeWithPolicy")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetLogFileSizeWithPolicy([In] HLOG hLog, in ulong pDesiredSize, out ulong pResultingSize); /// /// The LOG_MANAGEMENT_CALLBACKS structure is used to register with the Common Log File System (CLFS) for the callbacks that a /// client program requires information from. /// // https://docs.microsoft.com/en-us/windows/win32/api/clfsmgmtw32/ns-clfsmgmtw32-log_management_callbacks typedef struct // _LOG_MANAGEMENT_CALLBACKS { PVOID CallbackContext; PLOG_TAIL_ADVANCE_CALLBACK AdvanceTailCallback; PLOG_FULL_HANDLER_CALLBACK // LogFullHandlerCallback; PLOG_UNPINNED_CALLBACK LogUnpinnedCallback; } LOG_MANAGEMENT_CALLBACKS, *PLOG_MANAGEMENT_CALLBACKS; [PInvokeData("clfsmgmtw32.h", MSDNShortId = "NS:clfsmgmtw32._LOG_MANAGEMENT_CALLBACKS")] [StructLayout(LayoutKind.Sequential)] public struct LOG_MANAGEMENT_CALLBACKS { /// /// A pointer to the context which is a client-defined value. CLFS ignores this value other than to pass it with every callback to /// the client. /// public IntPtr CallbackContext; /// Called when the management functionality determines that the client should advance the tail of its log. [MarshalAs(UnmanagedType.FunctionPtr)] public PLOG_TAIL_ADVANCE_CALLBACK AdvanceTailCallback; /// Called when an asynchronous request is initiated when HandleLogFull completes. [MarshalAs(UnmanagedType.FunctionPtr)] public PLOG_FULL_HANDLER_CALLBACK LogFullHandlerCallback; /// Called when a pinned log becomes unpinned. [MarshalAs(UnmanagedType.FunctionPtr)] public PLOG_UNPINNED_CALLBACK LogUnpinnedCallback; } }