Is it safe to initialize MS HANDLE to nullptr?
c++, winapi
Solution
For handles that resolve to a pointer type you can use `nullptr` instead of `NULL`. A good number of handle types are `typedef`'d as pointers so you shouldn't run into much problem.
This does not mean it is ok to use either `NULL` or `nullptr`. Some calls return `INVALID_HANDLE_VALUE` which in VS2013 is defined as `((HANDLE)(LONG_PTR)-1)` and relying on a null value to indicate an invalid/unopen handle may cause problems. For instance `CreateFile` returns `INVALID_HANDLE_VALUE` instead of a zero or null value. All places in your code that assumes a null value indicates an unopened handle may cause problems.
Problem
I know using `nullptr` is more "typed". It can distinguish `pointer type` and `0` and works well in function overloading and template specialization. So I am not sure whether it is safe to replace the `NULL` to `nullptr` in my old Win32 project in every `HANDLE`/`HWND`/`HINSTNACE` initialization usages? Any suggestion will be helpful. Thanks