Search code examples
pythoncidl

Python int too large to convert to C long in Python COM


I have a python method that calculates value and returns it. The value is

CalcData = 3941269503L. 

It is only 32 bit. Yet this is typecasted to long implicitly (suffixed by L) and when I access this method in COM in other application , I get the Python int too large to convert to C long error. I even tried typecasting it into int,but no luck


Solution

  • The "long" C type is signed so the largest positive value it can store is 2,147,483,647. The error is indeed correct, it doesn't fit.

    Try "unsigned long" and "UL" postfix on the constant.