Note that there are some explanatory texts on larger screens.

plurals
  1. POCOM call : OverflowError: Python int too large to convert to C long
    primarykey
    data
    text
    <p>I'm trying to call a COM Method using win32com Python (v3.3) library. This method accepts an address and a data to write to that address.</p> <pre><code>SWDIOW(IN addr, IN data) </code></pre> <p>Problem is: accepted size for data is 32bits. When I call this method with such parameters there is no problem:</p> <pre><code>swdiow(0x400c0000, 0x00000012) </code></pre> <p>But when data is too big (actually greater than 2^(-31)-1), such as;</p> <pre><code>swdiow(0x400c0000, 0xF3804770) </code></pre> <p>This happens:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "C:\WinPython\python-3.3.2.amd64\lib\site-packages\win32com\gen_py\97FF1B53-6477-4BD1-8A29-ADDB58E862E5x0x16x0.py", line 1123, in swdiow , data) OverflowError: Python int too large to convert to C long </code></pre> <p>I think this problem happens because python takes 0xF3804770 as a signed integer. This value requires 32 bits to be represented as unsigned. To make it signed, Python adds one more sign bit, and size of 0xF3804770 becomes 33 bits. Because of that sign bit, it cannot convert to C long type which I believe the size is 32 bits.</p> <p>I've found a workaround to this that will convert number to a negative integer when it's too big.</p> <pre><code>&gt;&gt; int.from_bytes((0xF3804770).to_bytes(4,'big',signed=False),'big', signed=True) -209696912 </code></pre> <p>Maybe this is the best thing I could do, but I wonder if there is a more elegant solution to this?</p> <p>By the way, source of my 'data' is a text file that contains 4 bytes HEX values such as this;</p> <pre><code>D0010880 D1FD1E40 F3EF4770 431103C2 ... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload