Why does Windows use SetLastError/GetLastError - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Why does Windows use SetLastError/GetLastError

Why does the Windows API use the SetLastError/GetLastError model instead of just having functions return success or an error code? Is there any reason someone writing their own API for Win32 should use the Get/Set LastError model instead of just returning sucess or error code? Thanks.

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : Why does the Windows API use the SetLastError/GetLastError model
    : instead of just having functions return success or an error code? Is
    : there any reason someone writing their own API for Win32 should use
    : the Get/Set LastError model instead of just returning sucess or
    : error code? Thanks.
    :
    [color=Blue]The Win API is designed to return a TRUE/FALSE code as a signal of success or failure. A lot of APIs return a handle or pointer, which can be NULL or non-NULL value. This also translates to a success or failure return code.

    The ability to give the real reason of success or failure is very good for extending the API in next versions of Win API.[/color]
Sign In or Register to comment.