From 5ffcb79306139f20197b6492924bbe12a51d0ac2 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 31 Jan 2017 12:31:46 +0100 Subject: [PATCH] Over-matching win::event_data template constructor replaced with selected data type variants only; NULL strings presented as "" to work-around trouble with Event Viewer not rendering event parameters when some strings are NULL --- include/WinStd/ETW.h | 126 ++++++++++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 43 deletions(-) diff --git a/include/WinStd/ETW.h b/include/WinStd/ETW.h index c5f68a09..6cd915c1 100644 --- a/include/WinStd/ETW.h +++ b/include/WinStd/ETW.h @@ -99,77 +99,114 @@ namespace winstd /// - /// Template to construct class with generic data. + /// Construct class pointing to an `int`. /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \param[in] data Event data /// - template - inline event_data(_In_ const T &data) + /// \note This class saves a reference to the data only. Therefore, data must be kept available. + /// + inline event_data(_In_ const int &data) { - EventDataDescCreate(this, &data, (ULONG)(sizeof(T))); + EventDataDescCreate(this, &data, (ULONG)(sizeof(data))); } /// - /// Construct class with string. + /// Construct class pointing to an `unsigned int`. /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \param[in] data Event data + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. + /// + inline event_data(_In_ const unsigned int &data) + { + EventDataDescCreate(this, &data, (ULONG)(sizeof(data))); + } + + + /// + /// Construct class pointing to a `long`. + /// + /// \param[in] data Event data + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. + /// + inline event_data(_In_ const long &data) + { + EventDataDescCreate(this, &data, (ULONG)(sizeof(data))); + } + + + /// + /// Construct class pointing to an `unsigned long`. + /// + /// \param[in] data Event data + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. + /// + inline event_data(_In_ const unsigned long &data) + { + EventDataDescCreate(this, &data, (ULONG)(sizeof(data))); + } + + + /// + /// Construct class pointing to a `GUID`. + /// + /// \param[in] data Event data + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. + /// + inline event_data(_In_ const GUID &data) + { + EventDataDescCreate(this, &data, (ULONG)(sizeof(data))); + } + + + /// + /// Construct class pointing to a string. + /// + /// \param[in] data Event data. When `NULL`, the event data will be `""`. + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. /// inline event_data(_In_ const char *data) { if (data) EventDataDescCreate(this, data, (ULONG)((strlen(data) + 1) * sizeof(*data))); - else - EventDataDescCreate(this, NULL, 0); + else { + // Writing NULL pointer with 0B length causes trouble in Event Viewer: message template string is displayed only, parameters are not rendered. + static const char null[] = ""; + EventDataDescCreate(this, null, sizeof(null)); + } } /// - /// Construct class with string. + /// Construct class pointing to a wide string. /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \param[in] data Event data. When `NULL`, the event data will be `""`. /// - inline event_data(_In_ char *data) - { - if (data) - EventDataDescCreate(this, data, (ULONG)((strlen(data) + 1) * sizeof(*data))); - else - EventDataDescCreate(this, NULL, 0); - } - - - /// - /// Construct class with wide string. - /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \note This class saves a reference to the data only. Therefore, data must be kept available. /// inline event_data(_In_ const wchar_t *data) { if (data) EventDataDescCreate(this, data, (ULONG)((wcslen(data) + 1) * sizeof(*data))); - else - EventDataDescCreate(this, NULL, 0); + else { + // Writing NULL pointer with 0B length causes trouble in Event Viewer: message template string is displayed only, parameters are not rendered. + static const wchar_t null[] = L""; + EventDataDescCreate(this, null, sizeof(null)); + } } /// - /// Construct class with wide string. + /// Template to construct pointing to a `std::basic_string<>`. /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \param[in] data Event data /// - inline event_data(_In_ wchar_t *data) - { - if (data) - EventDataDescCreate(this, data, (ULONG)((wcslen(data) + 1) * sizeof(*data))); - else - EventDataDescCreate(this, NULL, 0); - } - - - /// - /// Template to construct class with string. - /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \note This class saves a reference to the data only. Therefore, data must be kept available. /// template inline event_data(_In_ const std::basic_string<_Elem, _Traits, _Ax> &data) @@ -179,9 +216,12 @@ namespace winstd /// - /// Construct class with binary data. + /// Construct class pointing to binary data. /// - /// \note This class is saves a reference to the data only. Therefore, data must be kept available. + /// \param[in] data Pointer to event data + /// \param[in] size Size of \p data in bytes + /// + /// \note This class saves a reference to the data only. Therefore, data must be kept available. /// inline event_data(_In_bytecount_(size) const void *data, _In_ ULONG size) {