g_ usually denotes a global variable. The code (not .NET) provided in the Microsoft documentation and samples may use some version of Hungarian notation for historical reasons.
Systems Hungarian notation is not used very much, if at all, in C ++, since the compiler already knows the types of your variables. There is such a thing as the Hungarian Notation app, for which Joel Spolsky wrote an article about .
Now global variables are not a good idea in production code. Global variables are available everywhere, which means that they can be changed anytime, anywhere in your code. This easily becomes a nightmare for maintenance and debugging.
The reason you see them in the sample code is because the samples should be minimal, but compiled code snippets that demonstrate how to use the API. Note that the sample code also skips things like error checking for the same reason. The sample code does not necessarily demonstrate good coding methods or methods, although this is certainly possible.
In short, sample-style code becomes messy in any non-trivial application. In production code, you must create a structure and make the correct code design. This includes not using global variables.
source share