Skip to content

Commit

Permalink
Imported comtypes 0.2.1.
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : svn%3Aa2f44796-8cc0-49ac-b43f-6a96d556d52d/trunk%403
  • Loading branch information
thomas.heller committed Jul 11, 2006
0 parents commit 938fbd5
Show file tree
Hide file tree
Showing 51 changed files with 8,495 additions and 0 deletions.
59 changes: 59 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
2006-04-25 Thomas Heller <theller@python.net>

* Released version 0.2.1 (svn revision 8).

2006-03-07 Thomas Heller <theller@python.net>

* Imported comtypes from the ctypes CVS repository into the
comtypes SVN repository.

2006-03-03 Thomas Heller <theller@python.net>

* (Repository): Move the code generator modules into the
comtypes.tools package. Should be refactored later - most
important is now that it works again.

2006-02-11 Thomas Heller <theller@python.net>

* Merged in lots of changes from the upstream version. Started
localserver support.

2005-10-20 Thomas Heller <theller@python.net>

* comtypes\__init__.py: Add logging for easier debugging. Add
COINIT_... flags. Use the value of sys.coinit_flags (when
defined) in the call to CoInitializeEx, this allows to use
multithreaded appartments.

Clean up the lifetime management of implemented COM objects. Make
COM attribute access case insensitive (has a large impact on the
performance, unfortunately).

Move the COMObject definition in a separate module
comtypes\_comobject.py.

* comtypes\tools\codegenerator.py: Don't generate dispid() for
non-dispatch based interfaces.

* comtypes\client\__init__.py: Add logging for easier debugging.

* comtypes\persist.py: Remove dispid() from non-dispatch based
interfaces. Correct the Read method. Hack around the
POINTER(c_wchar) <-> c_wchar_p problem.

2005-10-11 Thomas Heller <theller@python.net>

* comtypes\client\__init__.py: Renamed CreateModule() into
GetModule(). Removed the 'modulename' parameter from all the
function calls - the typelib wrapper alias name is now taken from
the typelib library name. Suggestions from Bruce Dodson.

2005-09-29 Thomas Heller <theller@python.net>

* comtypes\GUID.py: Rename the GUID.progid() classmethod into
GUID.as_progid().

2005-09-02 Thomas Heller <theller@python.net>

* comtypes\client\__init__.py: Can now receive events from custom,
non-dispatch interfaces.
93 changes: 93 additions & 0 deletions comtypes/GUID.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from ctypes import *

BYTE = c_byte
WORD = c_ushort
DWORD = c_ulong

_ole32 = oledll.ole32

_StringFromCLSID = _ole32.StringFromCLSID
_CoTaskMemFree = _ole32.CoTaskMemFree
_ProgIDFromCLSID = _ole32.ProgIDFromCLSID
_CLSIDFromString = _ole32.CLSIDFromString
_CLSIDFromProgID = _ole32.CLSIDFromProgID
_CoCreateGuid = _ole32.CoCreateGuid

# Note: Comparing GUID instances by comparing their buffers
# is slightly faster than using ole32.IsEqualGUID.

class GUID(Structure):
_fields_ = [("Data1", DWORD),
("Data2", WORD),
("Data3", WORD),
("Data4", BYTE * 8)]

def __init__(self, name=None):
if name is not None:
_CLSIDFromString(unicode(name), byref(self))

def __repr__(self):
return u'GUID("%s")' % unicode(self)

def __unicode__(self):
p = c_wchar_p()
_StringFromCLSID(byref(self), byref(p))
result = p.value
_CoTaskMemFree(p)
return result
__str__ = __unicode__

def __cmp__(self, other):
if isinstance(other, GUID):
return cmp(buffer(self), buffer(other))
return -1

def __nonzero__(self):
return str(buffer(self)) != "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

def __eq__(self, other):
return isinstance(other, GUID) and \
buffer(self) == buffer(other)

def __hash__(self):
# We make GUID instances hashable, although they are mutable.
return hash(buffer(self))

def copy(self):
return GUID(unicode(self))

def from_progid(cls, progid):
"""Get guid from progid, ...
"""
if hasattr(progid, "_reg_clsid_"):
progid = progid._reg_clsid_
if isinstance(progid, cls):
return progid
elif isinstance(progid, basestring):
if progid.startswith("{"):
return cls(progid)
inst = cls()
_CLSIDFromProgID(unicode(progid), byref(inst))
return inst
else:
raise TypeError("Cannot construct guid from %r" % progid)
from_progid = classmethod(from_progid)

def as_progid(self):
"Convert a GUID into a progid"
progid = c_wchar_p()
_ProgIDFromCLSID(byref(self), byref(progid))
result = progid.value
_CoTaskMemFree(progid)
return result

def create_new(cls):
"Create a brand new guid"
guid = cls()
_CoCreateGuid(byref(guid))
return guid
create_new = classmethod(create_new)

assert(sizeof(GUID) == 16), sizeof(GUID)

__all__ = ["GUID"]

0 comments on commit 938fbd5

Please sign in to comment.