def i32(x):
    """Converts a long (for instance 0x80005000L) to a signed 32-bit-int.

    Python2.4 will convert numbers >= 0x80005000 to large numbers
    instead of negative ints.    This is not what we want for
    typical win32 constants.

    Usage:
        >>> i32(0x80005000L)
        -2147363168
    """
    # x > 0x80000000L should be negative, such that:
    # i32(0x80000000L) -> -2147483648L
    # i32(0x80000001L) -> -2147483647L     etc.
    return (x & 0x80000000 and -2 * 0x40000000 or 0) + int(x & 0x7fffffff)