0

I have an SDK that I should use. This SDK does not document the concrete dll files to be used. The C header files contain a class ids instead. There are also interface and class declarations. These may be used as parameters for exported functions and also as return values.

Example declaration:

const CLSID CLSID_Core2 = {0x1111111D,0x111D,0x99bc,{0x99,0x99,0x99,0x99,0x99,0x99,0xff,0xaa}};

From the C program it is used like this:

CComPtr<ICatalog> tprogrammers;

hr = m_Core.CoCreateInstance(CLSID_Core2);
hr = m_Core->get_Programmers(&tprogrammers);

The CComPtr and ICatalog classes are defined elsewhere. CComPtr is built into windows ( https://msdn.microsoft.com/hu-hu/library/ezzw7k98.aspx ) but ICatalog is defined in a header file that is part of the SDK. The SDK contains lots of header files with interfaces and class ids, but it does not contain any implementation (C or CPP files).

Is there a chance that I can use these header files and use the installed SDK from Python?

nagylzs
  • 3,954
  • 6
  • 39
  • 70
  • 1
    I'm not super familiar with python, but I think you'll have to use the `comtypes` package: http://pythonhosted.org/comtypes/ (PS: CComPtr is not build into Windows, it's a helper class provided with Visual Studio) – Simon Mourier Aug 17 '17 at 15:11
  • The comtypes package seems to be the best solution. Please post it as an answer and I'm going to accept it. – nagylzs Aug 25 '17 at 08:55

2 Answers2

1

You will have to use the comtypes package: http://pythonhosted.org/comtypes/ that supports IUnkwown* (or "early-binding") interfaces, contrary to pywin32 that only supports IDispatch* (or "late-binding") interfaces.

PS: CComPtr is not build into Windows, it's a helper class provided with Visual Studio VC++ files.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
0

There is no need to use the CLSID to create an object. Just use the human readable ProgID to create the object.

AFAIK Phython uses late binding (IDispatch interface), so the interface definitions are not needed here.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • Not every COM class has a ProgId. Not every COM class is accessible by IDispatch (in fact many are not). – Simon Mourier Aug 17 '17 at 15:09
  • You are right. But AFAIK using Python it must have one and must use late binding. That what I know, may be I am wrong. https://stackoverflow.com/questions/1065844/what-can-you-do-with-com-activex-in-python – xMRi Aug 17 '17 at 15:52
  • 1
    `comtypes` allows non IDispatch interfaces, contrary to `pywin32` – Simon Mourier Aug 17 '17 at 16:58