nagylzs
nagylzs

Reputation: 4180

How to open a library with ctypes, using CLSID values and C++ header files?

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?

Upvotes: 0

Views: 593

Answers (2)

Simon Mourier
Simon Mourier

Reputation: 138960

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.

Upvotes: 1

xMRi
xMRi

Reputation: 15365

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.

Upvotes: 0

Related Questions