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

Refactor Function BOOLEAN GUIDsAreEqual(...) in wpc.cpp #2

Open
CyberPlaton opened this issue Feb 6, 2022 · 1 comment
Open

Refactor Function BOOLEAN GUIDsAreEqual(...) in wpc.cpp #2

CyberPlaton opened this issue Feb 6, 2022 · 1 comment

Comments

@CyberPlaton
Copy link

The function can be written as

bool GUIDsAreEqual(In const GUID* pGUIDAlpha, In const GUID* pGUIDOmega)
{
RPC_STATUS status = ERROR_TIMEOUT;

return (UuidEqual((UUID*)pGUIDAlpha, (UUID*)pGUIDOmega, &status) == RPC_S_OK) ? true : false;

}

and if we dont need to use status at all we can pass a nullptr instead of status.

On the other hand, if it is necessary to print out the status,
as here printf("GUIDsAreEqual : UuidEqual() [status %#x]", status);, consider refactoring the function like

bool GUIDsAreEqual(In const GUID* pGUIDAlpha, In const GUID* pGUIDOmega, RPC_STATUS* status)
{
return (UuidEqual((UUID*)pGUIDAlpha, (UUID*)pGUIDOmega, status) == RPC_S_OK) ? true : false;
}

Both alternatives will reduce the size and increase readability, as well as removing the goto statement.

@kouzhudong
Copy link
Owner

Yes, you are right.
This function is really a bit bloated and can be stripped down, stripped down like you did.
This code is taken from: Windows-driver-samples\network\trans\WFPSampler

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

No branches or pull requests

2 participants