enthought / enthought/comtypes

CreateObject fails and then suceeds

Open
#193 6 comments 0 reactions 0 assignees View on GitHub
64-bit enhancement
Dominant language
Python
Stars
345
Forks
105
PR merge metrics
No merged PRs in 30d

Description

I am working with a com library provided by a third party.
If I run in the python interpreter
```
>>> fac_client = CreateObject("CxFac.FacClient")
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
in
----> 1 fac_client = CreateObject("CxFac.FacClient")

~\anaconda3\envs\pycygnet\lib\site-packages\comtypes\client\__init__.py in CreateObject(progid, clsctx, machine, interface, dynamic, pServerInfo)
236 logger.debug("CoCreateInstance(%s, clsctx=%s, interface=%s)",
237 clsid, clsctx, interface)
--> 238 obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
239 else:
240 logger.debug("CoCreateInstanceEx(%s, clsctx=%s, interface=%s, machine=%s,\

~\anaconda3\envs\pycygnet\lib\site-packages\comtypes\__init__.py in CoCreateInstance(clsid, interface, clsctx, punkouter)
1223 p = POINTER(interface)()
1224 iid = interface._iid_
-> 1225 _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
1226 return p
1227

OSError: exception: access violation reading 0x0000000000000008
```
But if I run that same command a second time
```
fac_client = CreateObject("CxFac.FacClient")
```
Then there is no error and the Object is created correctly.

This happens in my program and I have had to work around this by
```
try:
CreateObject("CxFac.FacClient")
except OSError:
CreateObject("CxFac.FacClient")

fac_client = CreateObject("CxFac.FacClient")
```
Do you have any suggestions on how to determine what is causing the access violation and how to stop it?

I have also tried using ```GetModule``` on the dll, but that doesn't allow me to return the object

```
GetModule("CxFac64.dll")
from comtypes.gen import CxFacLib
fac_client = CxFacLib.IFacClient()
fac_client.UserId()
TypeError: Expected a COM this pointer as first argument
```

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.