Re: Change in PyWin32 API between 3.0x and 3.11 ?
"Christoph J. Dorner via python-win32" <[email protected]> Mon, 27 Oct 2025 19:37:19 +0100
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Organization | privat |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============8725517274565874312==
Content-Type: multipart/alternative;
boundary="------------dyshD4n48nbAe0KVuoIzOUIJ"
Content-Language: de-DE
This is a multi-part message in MIME format.
--------------dyshD4n48nbAe0KVuoIzOUIJ
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Hi there,
who ever might be interested:
openchat + some code analysis helped to find the solution:
def generate_typelib(appCOMclass:str) ->None:
""" generate_typelib - generate typelib if not pre-generated as requi=
red=20
by COM wrapper (dynamic dispatch does not work) Args: appCOMclass (str):=
=20
ProgID / COM class of Microsoft Office host application """ try:
# get TypeInfo typeinfo =3D win32com.client.Dispatch(appCOMclass)=
._oleobj_.GetTypeInfo(0)
# extract the TypeLib and index typelib,index =3Dtypeinfo.GetCont=
ainingTypeLib()
# get the TypeLib attributes typelib_attr =3Dtypelib.GetLibAttr()
# generate module win32com.client.gencache.EnsureModule(typelib_a=
ttr[0],typelib_attr[1],typelib_attr[3],typelib_attr[3])
print(f"Successfully generated the makepy module for TypeLibCLSID=
{typelib_attr[0]}belonging to ProgID / COM class '{appCOMclass}'.")
except Exception as e:
print(f"Error during generation of makepy module for TypeLibCLSID=
{typelib_attr[0]}belonging to ProgID / COM class '{appCOMclass}': {e}")
BTW: while I am pretty impressed by what AI namely chatGPT delivers with=
=20
regard to Python code snippets, it is quite a bit away from being flawless=
.
Regards
Chris
Am 27.10.2025 um 09:00 schrieb Christoph J. Dorner via python-win32:
> Hi there,
>
> after some investigation I found the issue: the new version of PyWin32=
=20
> does not find the makepy generated Python module.
> So I also learned that my codes needs this pre-generated. I am afraid=20
> I had a lack of understanding how PyWin32 and COM work i e the=20
> difference between make-py-generated dispatch and a dynamic dispatch.
>
> So I need to initiate the makepy generation - but here comes my next=20
> problem: I work with an objext xxx.Application i. e.=20
> Excel.Application. However, the CLISD of this object is not the CLSID=20
> of the respective typelib and I would need this to initiate makepy for=
=20
> the typelib.
>
> Regards
> Christoph
>
>
> Am 26.10.2025 um 15:36 schrieb Christoph J. Dorner via python-win32:
>> Hi there,
>>
>> I discovered that an MSOffice wrapper, especially an EXCEL wrapper=20
>> does not work as I was used to anymore. I evaluated the COM-object=20
>> (or its _dispobj_ subobject) attributes _prop_map_get_ and=20
>> _prop_map_put. It seems they are gone. Instead there is a subobject=20
>> _olerepr_ with attributes propMapGet / propMapPut. However, these are=
=20
>> lazily evaluated i. e. this doesn't work as desired either.
>>
>> I recently upgraded to PyWin32 3.11 - not sure what I used before, a=20
>> pretty early 3.0x release at least.
>> Was there a change I am not aware of?
>>
>> Regards
>> Christoph
>> _______________________________________________
>> python-win32 mailing list -- [email protected]
>> To unsubscribe send an email to [email protected]
>> https://mail.python.org/mailman3//lists/python-win32.python.org
>> Member address: [email protected]
>
> _______________________________________________
> python-win32 mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/python-win32.python.org
> Member address: [email protected]
--------------dyshD4n48nbAe0KVuoIzOUIJ
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hi there,<br>
<br>
who ever might be interested:<br>
openchat + some code analysis helped to find the solution:<br>
<br>
<div style="background-color:#ffffff;color:#080808">
<pre style="font-family:'Consolas',monospace;font-size:8,3pt;"><span
style="color:#0033b3;">def </span><span style="color:#00627a;">generate_typelib</span>(<span
style="color:#000000;">appCOMclass</span>: <span
style="color:#000080;">str</span>) -> <span
style="color:#0033b3;">None</span>:
<span style="color:#8c8c8c;font-style:italic;">"""
</span><span style="color:#8c8c8c;font-style:italic;"> generate_typelib - generate typelib if not pre-generated as required by COM wrapper (dynamic dispatch does not work)
</span><span style="color:#8c8c8c;font-style:italic;">
</span><span style="color:#8c8c8c;font-style:italic;"> Args:
</span><span style="color:#8c8c8c;font-style:italic;"> appCOMclass (str): ProgID / COM class of Microsoft Office host application
</span><span style="color:#8c8c8c;font-style:italic;"> """
</span><span style="color:#8c8c8c;font-style:italic;"> </span><span
style="color:#0033b3;">try</span>:
<span style="color:#8c8c8c;font-style:italic;"># get TypeInfo
</span><span style="color:#8c8c8c;font-style:italic;"> </span><span
style="color:#000000;">typeinfo </span>= win32com.client.Dispatch(<span
style="color:#000000;">appCOMclass</span>)._oleobj_.GetTypeInfo(<span
style="color:#1750eb;">0</span>)
<span style="color:#8c8c8c;font-style:italic;"># extract the TypeLib and index
</span><span style="color:#8c8c8c;font-style:italic;"> </span><span
style="color:#000000;">typelib</span>, <span
style="color:#000000;">index </span>= <span style="color:#000000;">typeinfo</span>.GetContainingTypeLib()
<span style="color:#8c8c8c;font-style:italic;"># get the TypeLib attributes
</span><span style="color:#8c8c8c;font-style:italic;"> </span><span
style="color:#000000;">typelib_attr </span>= <span
style="color:#000000;">typelib</span>.GetLibAttr()
<span style="color:#8c8c8c;font-style:italic;"># generate module
</span><span style="color:#8c8c8c;font-style:italic;"> </span>win32com.client.gencache.EnsureModule(<span
style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">0</span>], <span style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">1</span>],<span style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">3</span>],<span style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">3</span>])
<span style="color:#000080;">print</span>(<span
style="color:#067d17;">f"Successfully generated the makepy module for TypeLibCLSID </span><span
style="color:#0037a6;">{</span><span style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">0</span>]<span style="color:#0037a6;">}</span><span
style="color:#067d17;"> belonging to ProgID / COM class '</span><span
style="color:#0037a6;">{</span><span style="color:#000000;">appCOMclass</span><span
style="color:#0037a6;">}</span><span style="color:#067d17;">'."</span>)
<span style="color:#0033b3;">except </span><span
style="color:#000080;">Exception </span><span
style="color:#0033b3;">as </span><span style="color:#000000;">e</span>:
<span style="color:#000080;">print</span>(<span
style="color:#067d17;">f"Error during generation of makepy module for TypeLibCLSID </span><span
style="color:#0037a6;">{</span><span style="color:#000000;">typelib_attr</span>[<span
style="color:#1750eb;">0</span>]<span style="color:#0037a6;">}</span><span
style="color:#067d17;"> belonging to ProgID / COM class '</span><span
style="color:#0037a6;">{</span><span style="color:#000000;">appCOMclass</span><span
style="color:#0037a6;">}</span><span style="color:#067d17;">': </span><span
style="color:#0037a6;">{</span><span style="color:#000000;">e</span><span
style="color:#0037a6;">}</span><span style="color:#067d17;">"</span>)</pre>
</div>
<br>
BTW: while I am pretty impressed by what AI namely chatGPT delivers
with regard to Python code snippets, it is quite a bit away from
being flawless.<br>
<br>
Regards <br>
Chris<br>
<br>
<br>
<div class="moz-cite-prefix">Am 27.10.2025 um 09:00 schrieb
Christoph J. Dorner via python-win32:<br>
</div>
<blockquote type="cite"
cite="mid:[email protected]">Hi there,
<br>
<br>
after some investigation I found the issue: the new version of
PyWin32 does not find the makepy generated Python module.
<br>
So I also learned that my codes needs this pre-generated. I am
afraid I had a lack of understanding how PyWin32 and COM work i e
the difference between make-py-generated dispatch and a dynamic
dispatch.
<br>
<br>
So I need to initiate the makepy generation - but here comes my
next problem: I work with an objext xxx.Application i. e.
Excel.Application. However, the CLISD of this object is not the
CLSID of the respective typelib and I would need this to initiate
makepy for the typelib.
<br>
<br>
Regards
<br>
Christoph
<br>
<br>
<br>
Am 26.10.2025 um 15:36 schrieb Christoph J. Dorner via
python-win32:
<br>
<blockquote type="cite">Hi there,
<br>
<br>
I discovered that an MSOffice wrapper, especially an EXCEL
wrapper does not work as I was used to anymore. I evaluated the
COM-object (or its _dispobj_ subobject) attributes
_prop_map_get_ and _prop_map_put. It seems they are gone.
Instead there is a subobject _olerepr_ with attributes
propMapGet / propMapPut. However, these are lazily evaluated i.
e. this doesn't work as desired either.
<br>
<br>
I recently upgraded to PyWin32 3.11 - not sure what I used
before, a pretty early 3.0x release at least.
<br>
Was there a change I am not aware of?
<br>
<br>
Regards
<br>
Christoph
<br>
_______________________________________________
<br>
python-win32 mailing list -- <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
To unsubscribe send an email to <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman3//lists/python-win32.python.org">https://mail.python.org/mailman3//lists/python-win32.python.org</a>
<br>
Member address: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
</blockquote>
<br>
_______________________________________________
<br>
python-win32 mailing list -- <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
To unsubscribe send an email to <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman3//lists/python-win32.python.org">https://mail.python.org/mailman3//lists/python-win32.python.org</a>
<br>
Member address: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<br>
</blockquote>
<br>
</body>
</html>
--------------dyshD4n48nbAe0KVuoIzOUIJ--
--===============8725517274565874312==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-win32 mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-win32.python.org
Member address: [email protected]
--===============8725517274565874312==--