using python and comtypes module

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

dre1983

  • Posts: 1
  • Joined: Tue May 27, 2025 1:34 pm
  • Real Name: Andre Philips

using python and comtypes module

PostTue May 27, 2025 1:53 pm

Anyone used the comtypes module with python ?

I can connect to the Atem using

import comptypes.gen.BMDSwitcherAPI as bmd
from comtypes import BSTR, GUID, IUnknown, byref, POINTER

discovery = comtypes.client.CreateObject(bmd.CBMDSwitcherDiscovery)
discovery_iface = discovery.QueryInterface(bmd.IBMDSwitcherDiscovery)
switcher, hr = discovery_iface.ConnectTo(BSTR("ip_address"))
#Where Ip_address has to be filled in of course

if hr !=0 or not switcher:
print(f"Connection failed: {hr}")
exit()

print("Connected to switcher", switcher.GetProductName())

But then I try doing

switcher.CreateIterator() which has to result in IBMDSwitcherInputIterator object interface being called ?
And then I try to apply:
For each IBMDSwitcherInput returned by IBMDSwitcherInputIterator::Next retrieve the input’s
unique Id using IBMDSwitcherInput::GetInputId and retrieve other properties of the input, such as the
input’s name, using IBMDSwitcherInput::GetShortName or IBMDSwitcherInput::GetLongName

Added info:
In the manual I see:
Windows
The main entry point to the Switcher API is the CBMDSwitcherDiscovery class. This class should be
obtained from COM using CoCreateInstance:
IBMDSwitcherDiscovery* switcherDiscovery = NULL;
CoCreateInstance (CLSID_CBMDSwitcherDiscovery, NULL, CLSCTX_ALL,
IID_IBMDSwitcherDiscovery, (void**)&switcherDiscovery));
On success, CoCreateInstance returns an HRESULT of S_OK and switcherDiscovery points to a new
IBMDSwitcherDiscovery object interface.

This part is ok and I can connect to the Atem and get some info

from comtypes import BSTR, GUID, IUnknown,byref,POINTER
import comtypes.gen.BMDSwitcherAPI as bmd

discovery_iface = comtypes.client.CreateObject(bmd.CBMDSwitcherDiscovery, interface=bmd.IBMDSwitcherDiscovery)
switcher, hr = discovery_iface.ConnectTo(BSTR("10.0.8.219"))

if hr != 0 or not switcher:
print(f"❌ Connect failed: {hr}")
exit()

print("✅ Connected to switcher:", switcher.GetProductName())
I was also able to create the BMDSwitcherAPI.py file from the BMDSwitcherAPI.tlb file.

When opening .tlb with oleviewer to chech the iid I see
[ odl, uuid(759CFA56-DE34-43C6-8E85-A8B4108A7E80), helpstring("Input Iterator") ] interface IBMDSwitcherInputIterator : IUnknown { HRESULT _stdcall Next([out] IBMDSwitcherInput** input); HRESULT _stdcall GetById( [in] int64 inputId, [out] IBMDSwitcherInput** input); };

Which means the iid = 759CFA56-DE34-43C6-8E85-A8B4108A7E80

Then in python I try to do:
input_iterator = POINTER(bmd.IBMDSwitcherInputIterator)()
IID_IBMDSwitcherInputIterator = GUID("{759CFA56-DE34-43C6-8E85-A8B4108A7E80}")

hr = switcher.CreateIterator(byref(input_iterator), IID_IBMDSwitcherInputIterator)
But then I get:
hr = switcher.CreateIterator(byref(input_iterator), IID_IBMDSwitcherInputIterator)
TypeError: call takes exactly 2 arguments (3 given)

And when I try to do:
input_iterator = POINTER(bmd.IBMDSwitcherInputIterator)()
IID_IBMDSwitcherInputIterator = GUID("{759CFA56-DE34-43C6-8E85-A8B4108A7E80}")

hr = switcher.CreateIterator(byref(IID_IBMDSwitcherInputIterator))

print(hr)
print(input_iterator)
It will show:
1338431089488 hr value
<POINTER(IBMDSwitcherInputIterator) ptr=0x0 at 1379e942cd0> input_iterator value

So any ideas what I'm doing wrong ?

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 5 guests