简体   繁体   English

在ANSI C中使用WinAPI和DWMApi

[英]Using WinAPI & DWMApi in ANSI C

I've got a question regarding writing applications for Windows. 我有一个关于为Windows编写应用程序的问题。 Can I use WinAPI and DWMApi (aero glass, ribbon, etc.) when programming in ANSI C? 在ANSI C中编程时,我可以使用WinAPI和DWMApi(航空玻璃,色带等)吗? I'm looking at MSDN right now and they use c++. 我现在正在看MSDN,他们使用的是c ++。

The Windows API is a C API and can be used with any compiler that supports the 'standard' calling convention. Windows API是一个C API,可以与任何支持“标准”调用约定的编译器一起使用。

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. 微软已经做出了将自己的C编译器置于生命支持上的战略决策,并且在使用Visual Studio时你仍然坚持使用C90(带有一些特定的扩展)。 You can use 3rd party compilers (GCC and Clang via MinGW, Pelles C) which support more modern language dialects. 您可以使用支持更多现代语言方言的第三方编译器(GCC和Clang via MinGW,Pelles C)。

Try it. 试试吧。

Most APIs actually ARE C-APIs; 大多数API实际上都是C-API; they just call it C++ because "nobody" really uses C anymore. 他们只是称它为C ++,因为“没人”真的使用C了。 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. 我也注意到偶尔的结构附加了附加功能,但绝对不是在Win32中,而且它们可能只是为#Cdef而去了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. 我不知道的事情是当与C一起使用时标题是否“安全”,以及库是否具有未编码的符号。 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. 但是,制作一个只调用单个Win32 API函数的简单C程序应该澄清这一点。

The Win32 API is accessible from many different toolsets. 可以从许多不同的工具集访问Win32 API。 All C compilers for Windows that I have ever come across can call all Win32 APIs. 我遇到的所有Windows编译器都可以调用所有Win32 API。 What's more all these C compilers can call COM APIs and even GDI+ which is a very C++ centric library. 更重要的是,所有这些C编译器都可以调用COM API,甚至是GDI +,这是一个非常以C ++为中心的库。 But MS provided a bridge for C clients to use. 但MS为C客户提供了一个桥梁。

So, in summary, choosing to use C will not deprive you of access to any part of Win32. 因此,总而言之,选择使用C不会剥夺您访问Win32的任何部分的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM