mhammond / pywin32

Python for Windows (pywin32) Extensions
4.9k stars 783 forks source link

IFolderView COM client #2181

Closed CristiFati closed 4 months ago

CristiFati commented 4 months ago

I was trying to correct [SO]: How to move desktop icons with python? (@CristiFati's answer), based on [SO]: How to move desktop icons using winapi on C? (@@IInspectable's answer) (which in turn is based on Raymond Chen's [MS.DevBlogs]: Manipulating the positions of desktop icons). All good till at one of the last steps:

folder_view = shell_view.QueryInterface(IID_IFolderView)

which failed because IFolderView is not wrapped by win32comext/shell/shell.pyd. So I investigated what needs to be done in order to add it, and found out about MakeGW. Unfortunately that seems no longer maintained (worked on a side quest: #2180), and the generated files need lots of interventions, so I (temporarily) abandoned this track.

Looking for alternatives (based on [SO]: Implementing a COM interface in Python (@@SimonMourier's answer)), I defined the interface and implementation in Python (using COMTypes), and do all kinds of attempts to register it with PythonCom (call functions from PyCom_RegisterClientType family in pythoncom310.dll), but I wasn;t successful, so I returned to the original approach.

Coming back to the 1st option, after modifying the script generator, and the generated code, I was able to get it working.

Notes:

But functionally, it's complete as the 2 missing methods can be worked around others.