#include <dwrite.h> in C++ works, but not in C

280 views Asked by At

A single-line test.c:

#include <dwrite.h>

From the visual studio command prompt,

compiled as C++ works: cl /c /Tp test.c

compiled as C does not: cl /c test.c

First, I get a bunch of errors as this one:

C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um\dwrite.h(671): error C2059: syntax error: ':'

The line 671 is as follows:

interface DWRITE_DECLARE_INTERFACE("739d886a-cef5-47dc-8769-1a8b41bebbb0") IDWriteFontFile : public IUnknown

preprocessed to C++

struct __declspec(uuid("739d886a-cef5-47dc-8769-1a8b41bebbb0")) __declspec(novtable) IDWriteFontFile : public IUnknown

preprocessed to C

struct   IDWriteFontFile : public IUnknown

and the part " : public IUnknown" gets in the way. How am I supposed to fix this?

Then I get an error on line 1037: error C2061: syntax error: identifier 'IDWriteGeometrySink'

interface ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;

preprocessed to C

struct ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;

Finally, a bunch of errors involving static_cast which C does not have.

All in all, is dwrite.h not suitable for C? Using Visual Studio Community 2022. Does it work in any previous versions?

What I'm trying to do is compile https://github.com/makuke1234/PongD2D

1

There are 1 answers

2
arrowd On

C doesn't have inheritance, so this header is most likely C++ only.

The project you linked uses D2D from .cpp files and wraps C++ interface into C.