0
from win32com.client import gencache
gencache.EnsureModule('{00020813-0000-0000-C000-000000000046}', 0, 1, 2)

The script generates early binding for the application with the clsid {00020813-0000-0000-C000-000000000046}.

In the book Python Programming on Win32 it says the third and fourth values are the major and minor respectively.

I have no idea what this means and the documentation is rather poor.

HKey Directory

Borut Flis
  • 15,715
  • 30
  • 92
  • 119
  • Look under registry key HKEY_CLASSES_ROOT\TypeLib\[id] you will see one ore more keys. You can just use the major value and set minor to 0, unless you really want to point at the major + minor one. For example HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046} may display 1.9 (if Excel is installed) so you can use 1,0 for major,minor. {00000300-0000-0010-8000-00AA006D2EA4} (ADO) may give you two keys for ex : 2.8 and 6.0, so you can use 2,0 or 6,0. – Simon Mourier Mar 29 '21 at 18:16
  • So, the minor is always zero and the first value is the major? – Borut Flis Mar 30 '21 at 03:11
  • It is 1.9 in my case. – Borut Flis Mar 30 '21 at 03:23
  • I added the output of HKEY_CLASSES_ROOT\TypeLib\{CLSID} in the opening post. – Borut Flis Mar 30 '21 at 03:41
  • Yes, I have 1.9 too. What I mean is minor can be left as 0 in general so, major=1 and minor=0 will pick up 1.9 – Simon Mourier Mar 30 '21 at 06:09

1 Answers1

1

Looking at the source code for EnsureModule call, it's easy to see that it is the major/minor versions of the typelib. If they can't find it in the cache, then they load it like this:

pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid)

If you look at the Windows API for LoadRegTypeLib(),

HRESULT LoadRegTypeLib(
  REFGUID  rguid,
  WORD     wVerMajor,
  WORD     wVerMinor,
  LCID     lcid,
  ITypeLib **pptlib
);

wVerMajor

The major version of the library.

wVerMinor

The minor version of the library.

From https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-loadregtypelib

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • I don't know what values to use for major and minor. I updated the opening post with the value of HKEY_CLASSES_ROOT\TypeLib\{CLSID}. Your function assumes I know them. Furthermore, I don't what the minor and major versions are, what is the importance of their values. – Borut Flis Mar 30 '21 at 03:41
  • 1
    1.9 => major = 1, minor = 9. The '0" is the LCID. It should work to use a minor version smaller than what you have and the system will accept it. Not true for the major version. If you install the Windows SDK, which you should, it has a utility called oleview.exe that lets you inspect type libraries. – Joseph Willcoxson Mar 30 '21 at 04:36
  • 1
    I don't have Python in front of me. You are calling EnsureModule() with the first argument as a string. Does it want a string which represents a guid or a real guid? The other thing is the other arguments should then be 1,9,0 – Joseph Willcoxson Mar 30 '21 at 04:40
  • Interesting enough the value of version in HKLM:\software\classes\CLSID\{00020830-0000-0000-C000-000000000046} is 1.6, while in HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046} the folder is 1.9??? I don't know I have ran it with several different values for major, minor and no difference, I think I need to look at something else. – Borut Flis Apr 01 '21 at 17:14
  • Well, that function is for the version of the type library. IMHO, that "version" in the Excel Worksheet CLSID is some internal version that Microsoft uses. I do not think that is a standard key used by COM. It's the version of the Excel.Sheet and not of the typelib. They can be different. – Joseph Willcoxson Apr 01 '21 at 17:59