Skip to content

Conversation

@lianghaoGao
Copy link

No description provided.

@guhetier
Copy link
Contributor

guhetier commented May 1, 2023

Can you (in this PR or a follow up) update the "LatestBuild" with this new binary?
Or if you are motivated, moving those to an artifact in the "release" section of Github could be even better 😊

// typename C is the server object implementing IConnectionPoint to Advise()
// typename S is the client's sink object (must implement type T)
template <typename T, typename C, typename S>
void AdviseInProcObject(_In_ Microsoft::WRL::ComPtr<C> sourceObject, _In_ S* connectionSink)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could all the _In_ Foo* pointers be replaced with references? It avoids the need for SAL annotations and let the compiler enforce the `In requirement.

Copy link
Author

Choose a reason for hiding this comment

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

I don't have a strong opinion between pointer + SAL vs reference. It seems other project in this solution is using pointer + SAL. I'll keep this as is unless you have strong opinion to choose reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using references is part of the C++ coding guidelines, and since a sample aims to be used as an example, I think it's valuable to have this code to the best standard.

But the choice is up to you, I won't be annoying about this :)

Copy link
Author

Choose a reason for hiding this comment

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

Would you mind sharing the guidance you're referring to?

Copy link
Contributor

Choose a reason for hiding this comment

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

// typename C is the server object implementing IConnectionPoint to Advise()
// typename S is the client's sink object (must implement type T)
template <typename T, typename C, typename S>
void AdviseInProcObject(_In_ Microsoft::WRL::ComPtr<C> sourceObject, _In_ S* connectionSink)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sal not needed on non-pointer types


using namespace Microsoft::WRL;

std::wstring ToStringCheckingErrors(const std::wstring& errorString, const std::wstring& dataString)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be "noexcept" (and constexpr depending on the C++ std version)

ULONG fetched{0};
ComPtr<INetwork> network;
THROW_IF_FAILED(hr = enumConnectedNetworks->Next(1, network.GetAddressOf(), &fetched));
if (hr == S_OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply break on S_FALSE instead, and have a "while (true)" loop?
This would make the code simpler (no for loop without increment step, early break) and mostly clarify what success condition other than S_OK is expected there.

Copy link
Contributor

Choose a reason for hiding this comment

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

(an alternative, since you use this pattern a lot, could be a "map" function helper that applies a lambda to all the networks in the list)

SOCKADDR_STORAGE sockAddrStorage{};
if (pDestAddr)
{
memcpy(&sockAddrStorage, pDestAddr, sizeof(sockAddrStorage) > sizeof(*pDestAddr) ? sizeof(sockAddrStorage) : sizeof(*pDestAddr));
Copy link
Contributor

Choose a reason for hiding this comment

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

std::max rather than a ternary?

Also, shouldn't it be the min that is needed?

return returnString.empty() ? std::to_wstring(static_cast<int32_t>(connectivity)) : returnString;
}

inline std::wstring ToString(_In_ VARIANT* variant)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a reference?

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