Static dispatch

This tells you what to put in your python code:

(hello-rsa-python) PS D:\dev\source\local\rsa\python\hello-rsa-python> py .\venv\Lib\site-packages\win32com\client\makepy.py -i
Robot Object Model ver. 24.0
 {F3A37BD0-AA2D-11D2-9844-0080C86BE4DF}, lcid=0, major=1, minor=0
 >>> # Use these commands in Python code to auto generate .py support
 >>> from win32com.client import gencache
 >>> gencache.EnsureModule('{F3A37BD0-AA2D-11D2-9844-0080C86BE4DF}', 0, 1, 0)
(hello-rsa-python) PS D:\dev\source\local\rsa\python\hello-rsa-python>

This generates the python file for the entire library:

(hello-rsa-python) PS D:\dev\source\local\rsa\python\hello-rsa-python\makepy> py ..\venv\Lib\site-packages\win32com\client\makepy.py "Robot Object Model ver. 24.0"
Generating to C:\Users\johnsobr\AppData\Local\Temp\gen_py\3.11\F3A37BD0-AA2D-11D2-9844-0080C86BE4DFx0x1x0.py
Building definitions from type library...
Generating...
Importing module
(hello-rsa-python) PS D:\dev\source\local\rsa\python\hello-rsa-python>

So, putting this in a python module and running it…

from win32com.client import gencache

gencache.EnsureModule("{F3A37BD0-AA2D-11D2-9844-0080C86BE4DF}", 0, 1, 0)

creates the same library file in the same local temp directory as running the command line call:

makepy.py "Robot Object Model ver. 24.0"

The gencache.py has an EnsureModule() function and an EnsureDispatch(). The Dispatch variant seems to be a wrapper around EnsureModule(). I’m guessing there is a reason for this, but I fail to see it at this time nor understand when to use one over the other.

Brian Johnson @brian3johnson