0

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

aleksazr
  • 89
  • 7

1 Answers1

0

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.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • How? If you look into window.c, the first thing it does is #include "window.h", which then #includes "dwritewrapper.h", which #includes . I don't understand how that is a wrapper. CPP files call directX functions, but C files pass parameters to those CPP functions (say, DWRITE_FONT_WEIGHT_NORMAL in window.c). And DWRITE_FONT_WEIGHT_NORMAL is defined in dwrite.h as enum. – aleksazr Apr 15 '22 at 13:55
  • @aleksazr like it's been said already, you can't use dwrite.h from SDK with C code, it's not meant for that, as it's using C++ constructs. Specific workarounds that some projects use are unrelated to directwrite itself, you should consult project source. – bunglehead Apr 16 '22 at 05:12