digitalmars.D - D's IUnknown
- Chris Miller (25/25) Mar 16 2008 D has 2 IUnknown: one in std.windows.iunknown and another in
D has 2 IUnknown: one in std.windows.iunknown and another in std.c.windows.com. std.windows.iunknown's IUnknown is actually a class, which doesn't seem right. std.c.windows.com's IUnknown is an interface; but there's also a class ComObject implementing the IUnknown interface, and it's almost the same as std.windows.iunknown's IUnknown class. IUnknown probably shouldn't be a class, and I don't think ComObject is a part of the Windows C API. I think it should be changed to this: keep the IUnknown interface in std.c.windows.com (or perhaps std.c.windows.unknwn to match the Windows header), scrap std.windows.iunknown and move ComObject in its place (or perhaps std.windows.com) since it has safer interlocked refcounting. I also have a separate proposal for D's COM: Since ComObject is D's way into COM, my idea is to give its QueryInterface a default implementation that gets the D Object (using a new IID specifically for it). With this, D's casts could call QueryInterface on IUnknown and interfaces implementing it (T:IUnknown) and get the D Object. If the IUnknown wasn't created with D's ComObject, the QueryInterface will safely fail, and the cast can return null. This way, as far as a D user is concerned, IUnknown works like a regular D interface. D's interfaces were originally designed to work with COM but changed to work better with D. If my idea is possible, it would bring interfaces a step closer to that original goal. - Chris Miller (the original)
Mar 16 2008