1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    How to use HRESULT in C function ?

    how can i write a function to return HRESULT, i Don't know what is HRESULT and how should it be used for, googled it and found that, HRESULT can be used to represent the error condition in our program, will not go deep it those bit values, but what i understood was
    1. 0 or positive number indicates sucess
    2. negative number will indicate failure

    My Scenario, I have the following structure
    struct NODE
    NODE* pLeft;
    NODE* pRight;

    Now I want to write a function
    HRESULT TreeHasDepth(NODE* pNode, int depth)
    // my code here

    In above function,
    1. if depth of tree is equal to the given value of depth passed
    2. if depth of tree is greater than the given argument passed
    3. if depth is less than the given value of integer passed
    4. if the tree is null

    For the above scenarios to be tested, probably we will have to override HRESULT, can someone help me to understand how can we do it ?

  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    Talk to your tutor and find out what they meant.

    HRESULT is so widely used for so many things as to make it a useless idea without some context.

    The best I could figure out would be
    bool TreeHasDepth(NODE* pNode, int depth)
    Which would return true if the tree is at least 'depth' levels deep at the given root node, or false otherwise.

    Comments on this post

    • jwdonahue agrees : It does seem peculiar to prescribe HRESULT in such an assignment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Rep Power
    According to the all knowing Wikipedia: HRESULT is most commonly associated with a particular kind of API return type used in OS/2 and Microsoft Windows (essentially an array of bit fields and codes). I wouldn't think a school assignment on data structures would prescribe such a thing. Take Salem's advice and ask your instructor to clarify exactly what an HRESULT is supposed to be.
    I no longer wish to be associated with this site.

IMN logo majestic logo threadwatch logo seochat tools logo