Question

I've got a question regarding writing applications for Windows. Can I use WinAPI and DWMApi (aero glass, ribbon, etc.) when programming in ANSI C? I'm looking at MSDN right now and they use c++.

Was it helpful?

Solution

The Windows API is a C API and can be used with any compiler that supports the 'standard' calling convention.

Microsoft has made the strategic decision to put their own C compiler on life support, though, and you're stuck with C90 (with some specific extension) when using Visual Studio. You can use 3rd party compilers (GCC and Clang via MinGW, Pelles C) which support more modern language dialects.

OTHER TIPS

Try it.

Most APIs actually ARE C-APIs; they just call it C++ because "nobody" really uses C anymore. I've also noticed the occasional struct with additional functions attached to them, but definitely not in Win32, and they might just #ifdef that away for C.

The thing I don't know right away is whether the headers are "safe" when used with just C, and whether the libraries have unmangled symbols. I would assume they are, but one never knows. However, making a simple C program that just calls a single Win32 API function should clarify that.

The Win32 API is accessible from many different toolsets. All C compilers for Windows that I have ever come across can call all Win32 APIs. What's more all these C compilers can call COM APIs and even GDI+ which is a very C++ centric library. But MS provided a bridge for C clients to use.

So, in summary, choosing to use C will not deprive you of access to any part of Win32.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top