@@ -56,16 +56,20 @@ TRACELOGGING_DEFINE_PROVIDER(telemetry_provider_handle, "Microsoft.ML.ONNXRuntim
5656 (0x3a26b1ff , 0x7484 , 0x7484 , 0x74 , 0x84 , 0x15 , 0x26 , 0x1f , 0x42 , 0x61 , 0x4d ),
5757 TraceLoggingOptionMicrosoftTelemetry ());
5858
59- std::string WideToUtf8 (const std::wstring& wide) {
59+ std::string ConvertWideStringToUtf8 (const std::wstring& wide) {
6060 if (wide.empty ())
6161 return {};
6262
63- int utf8_length = ::WideCharToMultiByte (CP_UTF8, 0 , wide.data (), static_cast <int >(wide.size ()), nullptr , 0 , nullptr , nullptr );
63+ const UINT code_page = CP_UTF8;
64+ const DWORD flags = 0 ;
65+ LPCWCH const src = wide.data ();
66+ const int src_len = static_cast <int >(wide.size ());
67+ int utf8_length = ::WideCharToMultiByte (code_page, flags, src, src_len, nullptr , 0 , nullptr , nullptr );
6468 if (utf8_length == 0 )
6569 return {};
6670
6771 std::string utf8 (utf8_length, ' \0 ' );
68- if (::WideCharToMultiByte (CP_UTF8, 0 , wide. data (), static_cast < int >(wide. size ()) , utf8.data (), utf8_length, nullptr , nullptr ) == 0 )
72+ if (::WideCharToMultiByte (code_page, flags, src, src_len , utf8.data (), utf8_length, nullptr , nullptr ) == 0 )
6973 return {};
7074
7175 return utf8;
@@ -83,8 +87,9 @@ std::string GetServiceNamesForCurrentProcess() {
8387 DWORD bytes_needed = 0 ;
8488 DWORD services_returned = 0 ;
8589 DWORD resume_handle = 0 ;
86- if (!::EnumServicesStatusExW (service_manager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, nullptr , 0 , &bytes_needed,
87- &services_returned, &resume_handle, nullptr ) && ::GetLastError () != ERROR_MORE_DATA) {
90+ if (!::EnumServicesStatusExW (service_manager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, nullptr , 0 , &bytes_needed,
91+ &services_returned, &resume_handle, nullptr ) &&
92+ ::GetLastError () != ERROR_MORE_DATA) {
8893 ::CloseServiceHandle (service_manager);
8994 return ;
9095 }
@@ -98,7 +103,7 @@ std::string GetServiceNamesForCurrentProcess() {
98103 auto * services = reinterpret_cast <ENUM_SERVICE_STATUS_PROCESSW*>(buffer.data ());
99104 services_returned = 0 ;
100105 resume_handle = 0 ;
101- if (!::EnumServicesStatusExW (service_manager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL , reinterpret_cast <LPBYTE>(services),
106+ if (!::EnumServicesStatusExW (service_manager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE , reinterpret_cast <LPBYTE>(services),
102107 bytes_needed, &bytes_needed, &services_returned, &resume_handle, nullptr )) {
103108 ::CloseServiceHandle (service_manager);
104109 return ;
@@ -119,7 +124,7 @@ std::string GetServiceNamesForCurrentProcess() {
119124
120125 ::CloseServiceHandle (service_manager);
121126
122- service_names = WideToUtf8 (aggregated);
127+ service_names = ConvertWideStringToUtf8 (aggregated);
123128 });
124129
125130 return service_names;
0 commit comments