Windows Programming for beginners

Hi

I´m an experienced C++ programmer, but always developed software using Linux.
Now I need to develop some systems for Windows. My focus is the back end, like handling video, sound and networking. I´m not focused on developing GUI.
I´ve read many articles on the interne, but I still need many directions.
For instance, how to set up Windows for software development (besides using VisualStudio)?
What is COM and how to use it?
What is DirectX?
What is the difference between Win32 and UWP?
And what about .NET?

Microsoft description of APIs is very poor, and I can´t find any example of how to use many of them.

I´m sure I can find the answer for each of these questions on sparse sites on the internet, but I read an article and I see I need to understand many other new concepts before understanding it.
Can anyone suggest any tutorial, book or course for an organized learning on how to program with C++ in Windows, covering concepts such as the above ones?
theForger's Win32 API Programming Tutorial
http://www.winprog.org/tutorial/

The WinAPI is HUGE, was created before C++ was created so it uses C, and it keeps evolving and changing.

One of the best books for learning the barest basics of how to program Windows for desktops is Charles Petzold's "Programming Windows, Fifth Edition."
https://www.amazon.com/Programming-Windows%C2%AE-Fifth-Developer-Reference/dp/157231995X/

It is old, and the WinAPI has changed in some substantial ways since it was originally published in 1998. Someone has taken the time and effort to modernize most of the original code:
https://github.com/recombinant/petzold-pw5e

There aren't a lot of resources other than MS for understanding how to deal with video, sound and networking. Books are outdated as soon as published.
.NET is MS managed run-time. It's mainly used by c# and vb.net as MS's alternative to Java. It can also be used by C++ as C++/cli which uses MS non-standard C++ extensions (such as boxing (^) for managed types). It's 'managed' in the sense that the run-time will automatically delete memory no longer used (similar to c++ std::shared_ptr) - unlike new/delete in C++ (or malloc/free in c). It can give access to a whole set of additional .net features (such as forms etc). However IMO if you want to use .net then you'd be better off using c# which was designed to use .net.

If you compile using WIN32 as c or C++ then you produce a .exe program. If you use UWP (Universal Window Platform) then you produce an app (not a stand-alone program) which can be used on different devices (based around .net I think).

There is also C++ winrt
https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt

which produces an app.

Re com
https://docs.microsoft.com/en-us/windows/win32/com/component-object-model--com--portal

Re DirectX
https://docs.microsoft.com/en-us/windows/win32/directx

If you're going to be programming for Windows using any MS library (including WIN32) then you really need to become expert at searching https://docs.microsoft.com/en-us/

Note that whatever you decide to use on top of C++ (or c# if you go that way), there is a massive learning mountain to climb.

Then there this the (some consider now outdated) MFC which comprises a set of C++ classes encompassing the c based WIN32 api's.

https://docs.microsoft.com/en-us/cpp/mfc/framework-mfc?view=msvc-170

To use WIN32 with VS, then make sure that you have installed the latest SDK as part of VS installation. If you want to use MFC, then this also has to be installed. Similar for c++/cli - this has to be installed separately. If you're not using windows gui then all you need to do is to include windows.h. You might also want to also have before the include:

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

which cuts down what parts of windows.h are actually included (speeds up compilation) and stops windows defining min/max macros which can interfere with std::min/std::max.

Note that you need to read carefully the documentation for every API used and note that some require additional include files (especially the network ones). Also for every function used you should always check that the function has completed OK. How to do this is documented for each function.

You also need to pay attention to whether you compile as unicode (based upon wchar_t (16 bits) ) or multi-byte character set (set under project properties/advanced). WIN32 uses a whole set of new defined types
https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types

note W refers to unicode, A for ansi (multi-byte) and T refers to the type set by whether UNICODE/_UNICODE is defined or not.

Most WIN32 functions have 2 versions - W for unicode and A for ansi. eg SetWindowText(). Like this it uses UNICODE to decide whether to use the unicode or ansi version. However SetWindowTextW() is the unicode version and SetWindowTextA() is the ansi version.

Another useful resource for WIN32 is http://www.flounder.com/ (particulalry MVP Tips).

Have fun!

Last edited on
At one time MS has the WinAPI SDK available as a download that included the support files needed to compile apps, documentation and copious examples. Now the documentation is online, or butchered in Visual Studio's Help app.
Last edited on
Programming reference for the Win32 API - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/api/

Shows an overview of what programming technologies are available with the WinAPI, including COM, Audio and Video, DX and more.
Last edited on
@lcmarincek,

If you are going to be developing WinAPI apps you should consider getting Visual Studio, hands down. 2019 if you are not using 64-bit Windows, 2022 if you are.

Yes, it is big, it is "bloated," but for development on Windows it is the best compiler/IDE available. It has for Windows the best debugger.

There is a free Community edition available, restrictions apply, with two paid commercial editions as well.
https://visualstudio.microsoft.com/downloads/

One nice aspect of VS is currently it is the sole compiler that is fully C++20 compliant, every other compiler is lacking features. Though the gap is closing.

If you haven't used VS before it can be a bit intimidating in the beginning.
the web can be confusing, but microsoft's developer documentation is really good once you get a feel for how to use it.

A ramble that may help some:
if you did not know it, 32 bit computers were sort a long, long period in computing history. In the early 90s, the cpus and systems were 32 bit (depending on how you define it) eg the 386 (a 30ish mhz processor that didn't have floating point on it) but the operating system (DOS) was 16 bit as was its GUI (much like linux today, the GUI was apart from the OS at that time) and all the software as well. It was all 16 bit; 32 bit needs (like using more of your ram) were met using smoke and mirrors to operate in 16 bit chunks. Then windows NT and windows 95 came out (in parallel, more or less) which moved the operating system and gui into a single entity, and everything was pushed to 32 bit. At that point microsoft had already put out what is known as MFC (microsoft foundation classes) which was an OOP library that let you develop GUI programs. This is STILL ALIVE AND ACTIVE. It should probably be killed, but because it was used for so many years, it was not killed off entirely to allow old code to continue to be maintained. From 1995 until a bit into the 2000s it was king, but well beyond that because users didn't really upgrade to 64 bit that quickly. A rough estimate (my guess, really) is that MFC dominated GUI programming on windows from about 1993 (it came out in 1992) until about 2010 and was still not unheard of by 2015 and even ongoing today. By 2010 to 2015 64 bit .net and the 'new' way of doing things were starting to be used, but the managed code junk was well hated by many and MFC continued to be used for many, many programs.

MFC, GDI and GDI plus and similar tools are 32 bit (but still work fine and are fairly simple to use for a small, simple GUI program).
.net managed code (has a lot of illegal in C++ ^ symbols for a quick way to recognize it) is the modern microsoft way.

So, one of the big questions you need to answer is whether you will use managed code or not or if you care either way.

directx is a close to the hardware (direct access) set of tools for hardware interfacing including graphics, sound, keyboard, mouse, controllers, and so on. It is still very much active and is up to date, though version 1.0 was from the 1995 era version 12 is current and for window 10/11 era. It is designed for performance, and delivers pretty well on that. It is possible, likely even, that you will use directx in your work for sound/video if you interact with the hardware for these.

I suggest avoiding win32 unless you need to target antique systems or work with legacy code. While all that stuff is still functional, it is a 64 bit world now and has been for a good long while.
Topic archived. No new replies allowed.