You need to add the privilege before you call CreateFile
.
Your error handling is a bit messed up too. There's no need for any calls to SetLastError
. You simply need to check the return values of the API call before you call GetLastError
. Only call GetLastError
if the docs say that it has meaning. In the case of SetFileShortName
, as is the case for many API calls, you only call GetLastError
when the API call returns FALSE
. So you should write:
if (!SetFileShortNameW(hFile, L""))
{
error = GetLastError();
// ...
}