comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Attempting to import comtypes.viewobject raises AssetionError

Open DManowitz opened this issue 1 year ago • 3 comments

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

DManowitz avatar Jan 02 '23 23:01 DManowitz

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.

junkmd avatar Jan 03 '23 00:01 junkmd

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 avatar Jan 03 '23 18:01 vasily-v-ryabov

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.

vasily-v-ryabov avatar Jan 03 '23 18:01 vasily-v-ryabov