Sane API design (AKA C's #ifdef hell)
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Mon Apr 20 18:01:03 UTC 2026
On 21/04/2026 5:57 AM, Kagamin wrote:
> On Friday, 17 April 2026 at 14:37:28 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Metadata generators can be quite good like with OpenGL, but there are
>> others... such as COM which are absolutely horrid c++ mixed
>> monstrosities. I'm still unsure if it was a good thing or not for
>> Walter to never implement it. It was part of D's original design
>> document to include support.
>
> Did I miss something? D supports COM, I wrote bindings for 7zip COM
> interfaces and it's as clean as you can get
> ```d
> interface IArchiveOpenCallback : IUnknown
> {
> enum ID=ArchiveIID(0x10);
> HRESULT SetTotal(in ulong* files, in ulong* bytes);
> HRESULT SetCompleted(in ulong* files, in ulong* bytes);
> }
>
> interface IProgress : IUnknown
> {
> enum ID=CommonIID(0, 5);
> HRESULT SetTotal(in ulong total);
> HRESULT SetCompleted(in ulong* completeValue);
> }
>
> interface IArchiveExtractCallback : IProgress
> {
> enum ID=ArchiveIID(0x20);
> HRESULT GetStream(uint index, ISequentialOutStream* outStream, int
> askExtractMode);
> HRESULT PrepareOperation(int askExtractMode);
> HRESULT SetOperationResult(int opRes);
> }
> ```
> granted, 7zip doesn't use ifdef hell.
There is more to COM than this.
https://learn.microsoft.com/en-us/windows/win32/com/idl-files
More information about the Digitalmars-d
mailing list