CreateDirectory2W failure is documented as zero (NULL), not INVALID_HANDLE_VALUE.
The authoritative Microsoft contract available here is the Return value section for CreateDirectory2W, which states:
- success: nonzero
- failure: zero
- extended error: call
GetLastError
That matches the older CreateDirectory, CreateDirectoryW, and CreateDirectoryA documentation in the provided material, which all also say:
- success: nonzero
- failure: zero
-
GetLastErrorfor extended error information
So for CreateDirectory2W, the supported failure test is:
if (result == NULL) {
DWORD err = GetLastError();
}
INVALID_HANDLE_VALUE is the documented failure sentinel for APIs such as CreateFile3 and CreateFile2FromAppW, not for the CreateDirectory* functions shown here. The C6329 warning documentation reinforces that handle-returning APIs are not all checked the same way: CreateFile uses INVALID_HANDLE_VALUE, while the CreateDirectory* pages in this material use zero/nonzero success semantics.
Based on the provided Microsoft documentation, a returned nonzero value from CreateDirectory2W is the success case, and GetLastError should be used when the return value is zero.
The six-argument example discrepancy is not resolved by the provided material. The available documentation here only supports the five-parameter declaration and the zero-on-failure return contract.
References: