c++ win32, Is using UnregisterClass required when closing program?

Started by
2 comments, last by Skeleton_V@T 18 years, 1 month ago
Hi I was looking through some automatic window code generated by Visual c++ 2005 beta 2, and I noticed they didn't use UnregisterClass on the window's class. I usually call UnregisterClass when i close my app, but is it actually required to be called when the program is being shutdown? Thanks
Advertisement

According to MSDN:

- All window classes that an application registers are unregistered when it terminates.

So, it seems that it isn't necessary, perhaps just polite way of doing thing.
You don't need to, but I do. The main reason is that if I want to restart my app for any reason (as in re-create my CApp class), if the class is already registered, RegiserClassEx will fail, meaning I'd have to quit the application completely and restart it.
If you feel lazy, you may malloc bunches of memory, create several windows and threads then leave them while relying on the OS to do the cleaning up for you. It doesn't guarantee everything will be properly cleaned up, especially if your app is messing with other apps though. So, it is a good practice to properly alloc/free things as documented.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--

This topic is closed to new replies.

Advertisement