Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add process_iterator helper #509

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

asklar
Copy link
Member

@asklar asklar commented Mar 5, 2025

This adds a little iterator class to abstract away the toolhelp apis.

@asklar asklar requested a review from jonwis March 6, 2025 21:48
Comment on lines +16 to +21
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

#if (__WI_LIBCPP_STD_VER >= 17) && WI_HAS_INCLUDE(<string_view>, 1) // Assume present if C++17
#if defined(WIL_ENABLE_EXCEPTIONS)

#if __cpp_lib_string_view >= 201606L
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#if (__WI_LIBCPP_STD_VER >= 17) && WI_HAS_INCLUDE(<string_view>, 1) // Assume present if C++17
#if defined(WIL_ENABLE_EXCEPTIONS)
#if __cpp_lib_string_view >= 201606L
#include "common.h"
#if WIL_USE_STL && (__WI_LIBCPP_STD_VER >= 17) && WI_HAS_INCLUDE(<string_view>, 1) // Assume present if C++17
#include <string_view>
#endif
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && defined(WIL_ENABLE_EXCEPTIONS) && (__cpp_lib_string_view >= 201606L)

Use WIL_USE_STL to determine if it's okay to use the STL.

Need to include common.h for WIL_ENABLE_EXCEPTIONS and WIL_USE_STL definitions.

Need to include string_view to get the definition of __cpp_lib_string_view

#include <string>
#include <TlHelp32.h>

#define __WIL_PROCESS_ITERATOR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have an include guard, so this seems unnecessary

Comment on lines +44 to +48
DWORD ProcessID{};
ULONG_PTR ThreadCount{};
DWORD ParentProcessID{};
LONG BasePriority{};
std::wstring ProcessName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DWORD ProcessID{};
ULONG_PTR ThreadCount{};
DWORD ParentProcessID{};
LONG BasePriority{};
std::wstring ProcessName;
DWORD process_id{};
ULONG_PTR thread_count{};
DWORD parent_process_id{};
LONG base_priority{};
std::wstring process_name;

Use snake_case

};
} // namespace details

struct process_iterator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this an "iterator" when it's not actually an iterator is misleading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants