Metadata-Version: 2.4
Name: portacom
Version: 0.1.0
Summary: Call classic COM interfaces through ctypes on Windows, Linux and macOS
Author-email: Mahmoud Komaiha <mkomaiha@umich.edu>
License-Expression: MIT
Project-URL: Homepage, https://github.com/mkomaiha/portacom
Project-URL: Repository, https://github.com/mkomaiha/portacom
Project-URL: Issues, https://github.com/mkomaiha/portacom/issues
Project-URL: Changelog, https://github.com/mkomaiha/portacom/blob/main/CHANGELOG.md
Keywords: com,ctypes,winmd,iunknown,ffi,cross-platform
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# portacom

The runtime for bindings generated by
[winmd2py](https://pypi.org/project/winmd2py/): call classic (IUnknown-based)
COM interfaces through ctypes on Windows, Linux and macOS, and implement them
in Python. Pure Python, no dependencies.

```bash
pip install portacom
```

Generate bindings from a `.winmd` with `winmd2py`, then (here for MiniCOM's
example library on Linux, whose `BOOL` and BSTRs differ from Windows'):

```python
import ctypes, portacom

minicom = portacom.Abi("minicom", typedefs={"BOOL": ctypes.c_long}, allocator=portacom.PlainAllocator())
portacom.use_abi("my_bindings", minicom)  # before importing the bindings
import my_bindings.Example as example
import my_bindings.Registry as api

registry = portacom.co_create_instance(api.Registry, api.IRegistry, library="libExampleLib.so")
calc = registry.NewCalculator()  # [out] arguments are returned
print(calc.Add(1, 2))  # 3


class Callback(portacom.ComObject):  # implement an interface in Python
    _interfaces_ = (example.ICalcCb,)

    def Message(self, text):
        print("C++ says", text)


calc.SetCallback(Callback())
calc.QueryInterface(example.ICalc2).GetValue2()  # 43; C++ calls back: "C++ says GetValue2 called"
```

A failed HRESULT raises `portacom.COMError`. BSTRs, VARIANTs, SAFEARRAYs,
GUIDs and enums convert to and from Python values, and `portacom.Dispatch`
calls automation (IDispatch) objects by name.

For ready-made DirectX Shader Compiler bindings, see
[portacom-dxc](https://pypi.org/project/portacom-dxc/). Calling conventions,
ABI profiles and limitations are in the
[project README](https://github.com/mkomaiha/portacom#readme).

MIT license.
