enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
292 stars 98 forks source link

Attempting to import comtypes.viewobject raises AssetionError #446

Open DManowitz opened 1 year ago

DManowitz commented 1 year ago

When I try to import comtypes.viewobject, I get the following error:

  File "<stdin>", line 1, in <module>
  File "C:\Users\manow\miniconda3\envs\py37_ml_TfGpuMain\lib\site-packages\comtypes\viewobject.py", line 26, in <module>
    assert sizeof(tagLOGPALETTE) == 8, sizeof(tagLOGPALETTE)
AssertionError: 12

This occurs with comtypes 1.1.14 using Python 3.7 or 3.8

junkmd commented 1 year ago

comtypes.util is an old module that has not been maintained for a long time, the last modification being 14 years ago.

This package originator, Thomas Heller has stepped down from Python communities and I do not know his current contact information.

However, from the former change diff, it appears that this was migrated from a .py file originally generated in comtypes/gen. The reason I think so is that the first commit did not import IUnknown from comtypes, but from comtypes.gen._00020430_0000_0000_0000_C000_00000000000046_0_2_0. If these were defined from scratch, there would be no need for such roundabout imports.

So perhaps this was working well in the originator's 14 year old environment and is not so now.

I am not sure that removing the assert size and alignment checks is the solution. It may be necessary to change the definitions of various stuffs.

I would like to hear from other participants in this community.

vasily-v-ryabov commented 1 year ago

It looks like old asserts are valid for 32-bit Python only. For 64-bit Python we need to add conditional asserts. I did similar job for pywinauto a long time ago (between 2010 and 2014).

@DManowitz do you see such issue in 32-bit Python?

vasily-v-ryabov commented 1 year ago

It's because of different POINTER size for 32- and 64-bit Python. Maybe using sizeof(POINTER) in asserts is much simpler than use of the condition.

junkmd commented 2 months ago

@DManowitz Are you still interested in this issue?