I’m toying with a little 2D game engine in C# and decided to use Direct2D and DirectWrite for rendering. I know there’s the Windows API Code Pack and SlimDX, but I’d really like to dig in and write an interface from scratch. I’m trying to do it without Managed C++, but Direct2D and DirectWrite don’t appear to use traditional COM objects. They define interfaces that derive from IUnknown, but there appears to be no way to actually use them from C# with COM interop. There are IIDs in d2d1.h, but no CLSID.
Of course, I’m really new to COM interop, so perhaps I’m just missing something. Can someone shed some light on this situation?
Got it. You can’t create the objects directly, but
d2d1.dllcontains an export calledD2D1CreateFactorythat returns anID2DFactoryinterface. Using this, you can implement a Direct2D wrapper without Managed C++.I won’t include all of the types, because they’re all defined in
d2d1.h, but here’s how to use the code to get a factory:Make sure your
ID2DFactoryinterface has the appropriateGuidandInterfaceType(ComInterfaceType.InterfaceIsIUnknown)attributes.