enthought / enthought/comtypes

Extending IClassFactory Interface in comtypes.servers for IClassFactory2

Open
#101 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
345
Forks
105
PR merge metrics
No merged PRs in 30d

Description

I attempted this but I keep getting "Procedure probably called with too many arguments (16 bytes in excess).

Any help on this? if we can get it to work I'll be opening a pull request to bring this into comtypes.

```
class IClassFactory2(comtypes.IUnknown):
_iid_ = comtypes.GUID("{B196B28F-BAB4-101A-B69C-00AA00341D07}")
_methods_ = [
comtypes.STDMETHOD(comtypes.HRESULT, "CreateInstance",
[ctypes.POINTER(comtypes.IUnknown),
ctypes.POINTER(comtypes.GUID),
ctypes.POINTER(ctypes.c_void_p)]),
comtypes.STDMETHOD(comtypes.HRESULT, "LockServer",
[ctypes.c_int]),
comtypes.STDMETHOD(comtypes.HRESULT, "CreateInstanceLic",
[ctypes.POINTER(comtypes.IUnknown),
ctypes.POINTER(comtypes.IUnknown),
ctypes.POINTER(comtypes.GUID),
ctypes.POINTER(comtypes.BSTR),
ctypes.POINTER(ctypes.c_void_p)])
]

def CreateInstance(self, punkouter=None, interface=None, dynamic=False):
# HRESULT CreateInstance(
# [in] IUnknown *pUnkOuter,
# [in] REFIID riid,
# [out] void **ppvObject
# );

if dynamic:
if interface is not None:
raise ValueError("interface and dynamic are mutually exclusive")
realInterface = comtypes.automation.IDispatch
elif interface is None:
realInterface = comtypes.IUnknown
else:
realInterface = interface
obj = ctypes.POINTER(realInterface)()
self.__com_CreateInstance(punkouter, realInterface._iid_, ctypes.byref(obj))
if dynamic:
return comtypes.client.dynamic.Dispatch(obj)
elif interface is None:
# An interface was not specified, so return the best.
return comtypes.client.GetBestInterface(obj)
# An interface was specified and obj is already that interface.
return obj

def CreateInstanceLic(self, punkouter=None, punkreserved=None, interface=None, key=''):
# HRESULT CreateInstanceLic(
# [in] IUnknown *pUnkOuter,
# [in] IUnknown *pUnkReserved,
# [in] REFIID riid,
# [in] BSTR bstrKey,
# [out] PVOID *ppvObj
# );

# if interface is None:
# realInterface = comtypes.IUnknown
# else:
# realInterface = interface

#p = ctypes.POINTER(interface)()
obj = ctypes.POINTER(interface)()
addr = ctypes.byref(obj)
iid = interface._iid_

bstr = comtypes.byref(comtypes.BSTR())
logger.info("CreateInstanceLic({}, {}, {}, {}, {})".format(punkouter, punkreserved, iid, bstr, addr))
self.__com_CreateInstanceLic(punkouter, punkreserved, iid, bstr, addr)

return obj
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.