writing DWORD values > 0x7ffffff

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

writing DWORD values > 0x7ffffff

Scott Leerssen-2
I'm trying to write a DWORD value to the registry using _winreg.SetValueEx and anything greater than 0x7fffffff yields a "ValueError: Could not convert the data to the specified type."  I've seen a few posts saying that taking the complement of the large integer (basically making it a negative value) satisfies the API and fools it into storing the value, but that has the same result in my experiments.  Any hints as to how to write large integers int a DWORD?

Python 2.7.2

Thanks,
Scott
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: writing DWORD values > 0x7ffffff

Tim Roberts
Scott Leerssen wrote:
> I'm trying to write a DWORD value to the registry using _winreg.SetValueEx and anything greater than 0x7fffffff yields a "ValueError: Could not convert the data to the specified type."  I've seen a few posts saying that taking the complement of the large integer (basically making it a negative value) satisfies the API and fools it into storing the value, but that has the same result in my experiments.  Any hints as to how to write large integers int a DWORD?

Ugly but functional:
   dw = struct.unpack('l',struct.pack('L', 0x80102030))[0]

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: writing DWORD values > 0x7ffffff

Scott Leerssen-2

On Mar 26, 2012, at 3:20 PM, Tim Roberts wrote:

> Scott Leerssen wrote:
>> I'm trying to write a DWORD value to the registry using _winreg.SetValueEx and anything greater than 0x7fffffff yields a "ValueError: Could not convert the data to the specified type."  I've seen a few posts saying that taking the complement of the large integer (basically making it a negative value) satisfies the API and fools it into storing the value, but that has the same result in my experiments.  Any hints as to how to write large integers int a DWORD?
>
> Ugly but functional:
>   dw = struct.unpack('l',struct.pack('L', 0x80102030))[0]

Thanks, that does the trick.

Scott

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: writing DWORD values > 0x7ffffff

Scott Leerssen-2
In reply to this post by Tim Roberts

On Mar 26, 2012, at 3:20 PM, Tim Roberts wrote:

> Scott Leerssen wrote:
>> I'm trying to write a DWORD value to the registry using _winreg.SetValueEx and anything greater than 0x7fffffff yields a "ValueError: Could not convert the data to the specified type."  I've seen a few posts saying that taking the complement of the large integer (basically making it a negative value) satisfies the API and fools it into storing the value, but that has the same result in my experiments.  Any hints as to how to write large integers int a DWORD?
>
> Ugly but functional:
>   dw = struct.unpack('l',struct.pack('L', 0x80102030))[0]

It looks like I need to employ the inverse of that when reading large values back out of the registry, since a simple QueryValueEx() on that value is a negative integer.

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: writing DWORD values > 0x7ffffff

Tim Golden-4
In reply to this post by Tim Roberts
On 26/03/2012 20:20, Tim Roberts wrote:
>    dw = struct.unpack('l',struct.pack('L', 0x80102030))[0]

Seconded: I've used almost exactly this incantation for various
Windows-y things for a few years now.

TJG
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32