[Python-Dev] UUID module
p.f.moore at gmail.com
Sat Jun 10 17:19:04 CEST 2006
On 6/10/06, Paul Moore <p.f.moore at gmail.com> wrote:
> On 6/10/06, Ka-Ping Yee <python-dev at zesty.ca> wrote:
> > ...so i looked at PEAK's getnodeid48() routine and borrowed the
> > Win32 calls from there, with a comment giving attribution to PEAK.
> Instead of using pywin32, could you use ctypes, as that's part of core
> Python? It looks like the only Win32 API you use is CoCreateGUID, so
> wrapping it should be doable...
Here's some sample code (taken from Thomas Heller's comtypes module)
>>> from ctypes import oledll, Structure, byref
>>> from ctypes.wintypes import BYTE, WORD, DWORD
>>> class GUID(Structure):
... _fields_ = [("Data1", DWORD),
... ("Data2", WORD),
... ("Data3", WORD),
... ("Data4", BYTE * 8)]
>>> guid = GUID()
<__main__.GUID object at 0x00978EE0>
<__main__.c_byte_Array_8 object at 0x00978E40>
I'm not sure what the int(...[-13,-1], 16) does (as it stands, it
fails for me - I think you need to put str() round the CreateGuid
call) but I *think* it's the equivalent of guid.Data1 above.
So, you'd have:
"""Get the hardware address on Windows using Win32 extensions."""
from ctypes import oledll, Structure, byref
from ctypes.wintypes import BYTE, WORD, DWORD
_fields_ = [("Data1", DWORD),
("Data4", BYTE * 8)]
guid = GUID()
Hope this is of use.
More information about the Python-Dev