Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Are NDIS drivers allowed to use C++?
The first question is easy: can NDIS drivers be written in C++? The answer: yes. In this case, NDIS doesn’t have any official stance on C++, so we just fall back on the WDK’s general rules. As of Windows Driver Kit 8, Microsoft officially supports using a subset of the C++ language in drivers. (“Subset? What subset?” There’s more precise information here.)
The inevitable follow-up question is more nuanced: should NDIS drivers be written in C++? The answer is: it depends. Here are some facts that will help you derive a more specific answer:
- The NDIS API is a C API. There is no NDIS API that magically gets better or worse when you’re coming from C++ versus C.
- The NDIS team has no future plans to make a feature that requires C++. We are well-aware that many of our developers are dedicated fans of C, and have strong opinions on C++. Don't worry — C isn’t going anywhere.
- The NDIS team may, in the future, add minor conveniences that only light up in C++. For example, the WDK macro ARRAYSIZE is defined differently for a C++ driver, which gives it better abilities to detect misuse with pointers. NDIS.H may start adding macros that offer minor improvements for C++ code, just like WDM.H already has today.
- Several major IHVs build their production NDIS miniport drivers using C++.
- Several major IHVs build their production NDIS miniport drivers using C.
- Microsoft builds some drivers in C and some drivers in C++.
- Our NDIS sample drivers are all in C. (This is largely for historical reasons, as these drivers were created before C++ was officially supported. If we were creating a new sample today, we’d consider writing it in C++.)
In summary, then, either language works fine, and it all comes down to a matter of your preference.