expand a win32 error code into a human readable message

def _win32_strerror(err):
    """ expand a win32 error code into a human readable message """

    # FormatMessage will allocate memory and assign it here
    buf = ctypes.c_char_p()
    FormatMessage(
        FORMAT_MESSAGE_FROM_SYSTEM
        | FORMAT_MESSAGE_ALLOCATE_BUFFER
        | FORMAT_MESSAGE_IGNORE_INSERTS,
        None,
        err,
        0,
        buf,
        0,
        None,
    )
    try:
        return buf.value
    finally:
        LocalFree(buf)