Reputation: 281
So I'm writing a Win32 program in plain C, and it uses Direct2D for drawing. So far, everything has worked out nicely considering this is my first major experiment with COM. I'm now moving on to using DirectWrite for font rendering, but it appears there's a roadblock. While Direct2D and most other COM objects have separate interfaces written for C and C++, DirectWrite only has C++ interfaces in the Windows SDK headers. I don't know if this is an oversight or a purposeful decision, but it seems like it should work fine in C if given the proper C-friendly headers. I figure if I write my own header for DirectWrite, I should be fine.
So this gets me to the meat of the question: how does one go about taking the C++-style code for a COM interface and convert it to C-friendly code? I've never created a COM interface myself, so I don't know how to write my own DirectWrite header for it. I tried looking at the C and C++ interface headers for Direct2D side-by-side for comparison, but it's a little tough to wrap my head around. Thanks folks!
Upvotes: 4
Views: 1373
Reputation: 14467
There is a perfect article explaining how to implement your own COM classes in plain C
http://www.codeproject.com/Articles/13601/COM-in-plain-C
Then the book "Inside COM" (Dale Rogerson, Microsoft Corp. Publication: ISBN:1-57231-349-8) is a wonderful reference for all of the COM black magic.
Basically, you've come at least half of the way since you're using Direct2D. DirectX and other COM headers are autogenerated so to use DirectWrite you might just figure out what exact interfaces and methods you need and write them by hand or using some simple parser/generator.
Upvotes: 3