Best way to handle PROPERTYKEYs in a Windows property handler RRS feed

  • Question

  • I'm creating a group of Windows property handlers.  In a property handler, Windows feeds your object a given PROPERTKEY structure, and then you get (or set) a file property depending on what that PROPERTYKEY is.

    The challenge is if your handler handles many PROPERTYKEYs in different ways, then you might be stuck making a long if-else ladder to deal with all the possible keys and situations.  And PROPERTYKEYs are structures (containing GUIDs), so they're not readily switchable.

    I was going to make a large std::unordered_map to associate the keys and my corresponding functions, but that's getting somewhat complex, especially because I'm creating a group of property handlers, and it's tricky to deal with all the function pointers and arguments.

    I was also thinking about hashing the supplied PROPERTYKEY so that it could just be used in a switch statement.  But in the end, I'm not sure if that'll be better.

    So I guess I'm wondering if anyone had any input on how to handle these PROPERTKEYs.  Are there any other options?  Is the fact that Windows made PROPERTYKEYs not inherently switchable a clue that this stuff should just be handled in an if-else?  Even with a lot of keys?  Would the compiler likely optimize the if-else ladder, or is that only done with a switch statement?  Thanks for any input.

    • Edited by amt528 Sunday, October 20, 2019 12:54 AM
    Sunday, October 20, 2019 12:53 AM

All replies

  • I'm not sure you've thought about this, but there's no "switch" statement in assembly language, so a "switch" statement gets compiled into a long list of if/else statements anyway.  Efficiency-wise, there's no difference.

    Just use the if/else tree.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, October 20, 2019 6:40 AM
  • Hi,

    When creating your own software you are unlikely to see a real performance problem between the if statement and the switch command. Unless you do see a performance problem you should always choose the option that makes the code more readable and maintainable.

    About switch and if-else performance, there are many cases for you to refer to in Stackoverflow forum. Such as this case.

    >>>But in the end, I'm not sure if that'll be better.

    You will konw only after you do it. 

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, October 21, 2019 2:41 AM