Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pep8 #403

Closed
wants to merge 28 commits into from
Closed

Pep8 #403

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pep8
kdschlosser committed Dec 6, 2022
commit 8dbf244fd5f5d80ab3465f3b68097cfe99d03a9a
58 changes: 39 additions & 19 deletions comtypes/git.py
Original file line number Diff line number Diff line change
@@ -4,54 +4,74 @@
between different threading appartments.
"""
from ctypes import *
from comtypes import IUnknown, STDMETHOD, COMMETHOD, \
GUID, HRESULT, CoCreateInstance, CLSCTX_INPROC_SERVER
from comtypes import (
IUnknown,
STDMETHOD,
GUID,
HRESULT,
CoCreateInstance,
CLSCTX_INPROC_SERVER
)

DWORD = c_ulong


class IGlobalInterfaceTable(IUnknown):
_iid_ = GUID("{00000146-0000-0000-C000-000000000046}")
_methods_ = [
STDMETHOD(HRESULT, "RegisterInterfaceInGlobal",
[POINTER(IUnknown), POINTER(GUID), POINTER(DWORD)]),
STDMETHOD(
HRESULT,
"RegisterInterfaceInGlobal",
[POINTER(IUnknown), POINTER(GUID), POINTER(DWORD)]
),
STDMETHOD(HRESULT, "RevokeInterfaceFromGlobal", [DWORD]),
STDMETHOD(HRESULT, "GetInterfaceFromGlobal",
[DWORD, POINTER(GUID), POINTER(POINTER(IUnknown))]),
]
STDMETHOD(
HRESULT,
"GetInterfaceFromGlobal",
[DWORD, POINTER(GUID), POINTER(POINTER(IUnknown))]
)
]

def RegisterInterfaceInGlobal(self, obj, interface=IUnknown):
cookie = DWORD()
self.__com_RegisterInterfaceInGlobal(obj, interface._iid_, cookie)
return cookie.value
ckie = DWORD()
self.__com_RegisterInterfaceInGlobal(obj, interface._iid_, ckie)
return ckie.value

def GetInterfaceFromGlobal(self, cookie, interface=IUnknown):
def GetInterfaceFromGlobal(self, ckie, interface=IUnknown):
ptr = POINTER(interface)()
self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr)
self.__com_GetInterfaceFromGlobal(ckie, interface._iid_, ptr)
return ptr

def RevokeInterfaceFromGlobal(self, cookie):
self.__com_RevokeInterfaceFromGlobal(cookie)
def RevokeInterfaceFromGlobal(self, ckie):
self.__com_RevokeInterfaceFromGlobal(ckie)


# It was a pain to get this CLSID: it's neither in the registry, nor
# in any header files. I had to compile a C program, and find it out
# with the debugger. Apparently it is in uuid.lib.
CLSID_StdGlobalInterfaceTable = GUID("{00000323-0000-0000-C000-000000000046}")

git = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
interface=IGlobalInterfaceTable,
clsctx=CLSCTX_INPROC_SERVER)
git = CoCreateInstance(
CLSID_StdGlobalInterfaceTable,
interface=IGlobalInterfaceTable,
clsctx=CLSCTX_INPROC_SERVER
)

RevokeInterfaceFromGlobal = git.RevokeInterfaceFromGlobal
RegisterInterfaceInGlobal = git.RegisterInterfaceInGlobal
GetInterfaceFromGlobal = git.GetInterfaceFromGlobal

__all__ = ["RegisterInterfaceInGlobal", "RevokeInterfaceFromGlobal", "GetInterfaceFromGlobal"]
__all__ = [
"RegisterInterfaceInGlobal",
"RevokeInterfaceFromGlobal",
"GetInterfaceFromGlobal"
]


if __name__ == "__main__":
from comtypes.typeinfo import CreateTypeLib, ICreateTypeLib

tlib = CreateTypeLib("foo.bar") # we don not save it later
tlib = CreateTypeLib("foo.bar") # we don not save it later
assert (tlib.AddRef(), tlib.Release()) == (2, 1)

cookie = RegisterInterfaceInGlobal(tlib)