Is this acceptable code?

Hello,
I've been learning c++ for quite some time now, and I thought it was about time that I actually make something useful. So I researched how to make a window in c++ with WinAPI, and I've followed the simple instructions provided by MSDN here: https://msdn.microsoft.com/en-us/library/bb384843.aspx What I'm wondering is this: Would the code they provided be accepted professionally? In other words, if you were to come across this written by someone (apart from the "Hello World" part of it), would you think, "What the heck? This code is terrible!" or is it pretty standard in all programs? I know that it is very simple beginner code for making a window, but I don't want to get in the habit of bad coding practices.
Last edited on
It's pretty standard in every win32 application. Here's another series of tutorials that looks more up to date IMO: https://msdn.microsoft.com/en-us/library/windows/desktop/ff381399%28v=vs.85%29.aspx
It's pretty standard in every win32 application. Here's another series of tutorials that looks more up to date IMO: https://msdn.microsoft.com/en-us/library/windows/desktop/ff381399%28v=vs.85%29.aspx


Wow, that's exactly what I've been looking for! Thanks for the help.

Also, I've watched a few of this guy's videos,
https://www.youtube.com/channel/UCaTznQhurW5AaiYPbhEA-KA
and he was programming in C mostly and was strongly against RAII. But many people were complaining that he wasn't releasing the resources he acquired after the program exited, and also doing other bad practices relating to handle leaking, etc. Do I need to worry about this, or does Windows handle most if it?
Generally yeah, if a windows function creates a resource then you are responsible for freeing it. If you're ever in doubt just look up the function on MSDN and in the remarks section it will tell you how to free the resource.
The Windows operating system will clear up all resources that a program (a process) owns, as I believe will Linux and most other major operating systems. (I don't work with mobile devices, but I gather the rules there might not be so clear cut?)

Some resources that a process uses are shared with other processes. In this case, the resource will only be freed when all processes that are using it are shut down.

But as a rule (there are always exceptions!) it is better practice to explicitly free all resource that a program acquired before exiting.

One case where it is helpful to free all resource (e.g. memory) is when runninf diagnostic tools on your program. If you see memory usage drop back to zero before exit you know you've cleaned everything up, and probably have no leaks.

Andy
Last edited on
Topic archived. No new replies allowed.