Experiments in early binding com object with D.
Dennis
dkorpel at gmail.com
Tue Nov 4 10:27:13 UTC 2025
On Monday, 3 November 2025 at 16:51:25 UTC, Vinod K Chandran
wrote:
> I was worrying that there is no com support except the basic
> building blocks like IUnknown and siblings. I know there is a
> com library in Adam's arsd. But I couldn't successfully use
> that. When I first tried Adam's library, I dreamed to write a
> com client in D one day. When time permitted, I slowly
> collected information about com and gradually made a confidence
> to start with early binding. I want to make my library high
> performance, so I choose early binding path.
I have succesfully made a D program connect to Excel using
arsd.com last year. My strategy was to ask ChatGPT to give
examples using Python win32com and then translate those calls to
D by sometimes adding extra parenthesis (because of limitations
of @property / opDispatch). The resulting code looks something
like this:
```D
const choice = cell.Value().getD!string.ifThrown!Exception("");
// ...
auto c1 = sheet.Cells()(varsRow + i, varsValueColumn);
c1.Formula() = "=" ~ cs;
c1.Interior().Color() = color;
```
It's using the dynamic IDispatch interface instead of static
bindings, which might be slower, but most calls take milliseconds
to complete anyways and I highly doubt that all that time is
spent on dynamic dispatch. The COM bridge and MS Office
applications seem to be the limiting factor.
I recommend to start with dynamic calls and maybe create bindings
from idl files later. If you explain what went wrong using
arsd.com maybe I or someone else can help.
More information about the Digitalmars-d-learn
mailing list