Skip to content

Modernize COM/HRESULT call idioms (try_query + WIL result macros) #38

Description

@asklar

Goal

Modernize the COM/HRESULT call idioms in the native code using WIL — purely a readability/consistency pass, no behavior change. Split out of #37 to keep that PR scoped to resource RAII (handles + BSTR/CoTaskMem).

This is polish, not a bug fix — low priority. Good to do whenever those files are being touched anyway.

Scope

  1. QueryInterface → try_query: replace x->QueryInterface(IID_PPV_ARGS(y.put())) with y = src.try_query<IY>() (when the source is a wil::com_ptr) or wil::try_com_query<IY>(raw) (raw source). ~6 sites, mainly src/tap/lvt_tap.cpp (~3), src/tap_wpf/wpf_tap_native.cpp (~1), plus any surfaced by Replace manual COM pointers with wil::com_ptr #24/Adopt wil/resource.h (wil::unique_*) for Win32 handles across the codebase #37.
  2. Manual if (FAILED(hr)) → WIL result macros (#include <wil/result.h>): RETURN_IF_FAILED, RETURN_HR_IF, RETURN_HR_IF_NULL, RETURN_LAST_ERROR_IF; LOG_IF_FAILED for void paths.

Hard constraints

  • TAP DLLs are /MT with no C++ exceptions — use ONLY the non-throwing families. NEVER THROW_* or FAIL_FAST_*.
  • Do NOT place these macros inside __try/__except SEH frames (SEH is isolated in thin wrappers like CollectBoundsForNodeSEH/SetSite; keep the macros in the pure-C++ bodies).
  • Behavior must be identical; keep build\lvt_unit_tests.exe + integration tests green.

Ordering

Do this after #24 (com_ptr) and #37 (handles+BSTR) land, so it layers cleanly on the finalized COM/HRESULT sites. One small, easy-to-review PR.

Relates to #10, #37.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions