Use <reinterpret_cast>()

This commit is contained in:
Jean Flach 2014-11-14 16:26:30 +01:00
parent e1b5954e62
commit 0054e78a58
4 changed files with 16 additions and 12 deletions

View File

@ -275,13 +275,13 @@ int check_drives(vector<drive>& vDrives)
while (GetLastError() != ERROR_NO_MORE_FILES) {
volumeNameEnd = wcslen(szVolumeName) - 1;
szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
while (!GetVolumePathNamesForVolumeName(szVolumeName, szVolumePathNames, dwVolumePathNamesLen, &dwVolumePathNamesLen)) {
if (GetLastError() != ERROR_MORE_DATA)
break;
delete[] szVolumePathNames;
szVolumePathNames = (PWCHAR) new BYTE[dwVolumePathNamesLen * sizeof(wchar_t)];
delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
szVolumePathNames = reinterpret_cast<wchar_t*>(new WCHAR[dwVolumePathNamesLen]);
}

View File

@ -239,13 +239,13 @@ int check_network(vector <nInterface>& vInterfaces)
err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
if (err == PDH_MORE_DATA || SUCCEEDED(err))
pDisplayValuesIn = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeIn];
pDisplayValuesIn = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
else
goto die;
err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
if (err == PDH_MORE_DATA || SUCCEEDED(err))
pDisplayValuesOut = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeOut];
pDisplayValuesOut = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwItemCount*dwBufferSizeIn]);
else
goto die;
@ -272,8 +272,8 @@ die:
if (phQuery)
PdhCloseQuery(phQuery);
if (pDisplayValuesIn)
delete pDisplayValuesIn;
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
if (pDisplayValuesOut)
delete pDisplayValuesOut;
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
return 3;
}

View File

@ -256,7 +256,7 @@ int countProcs(const wstring user)
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue;
pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength];
pSIDTokenUser = reinterpret_cast<PTOKEN_USER>(new BYTE[dwReturnLength]);
memset(pSIDTokenUser, 0, dwReturnLength);
if (!pSIDTokenUser)
@ -276,8 +276,8 @@ int countProcs(const wstring user)
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER)
continue;
AcctName = (LPWSTR) new wchar_t[dwAcctName];
DomainName = (LPWSTR) new wchar_t[dwDomainName];
AcctName = reinterpret_cast<LPWSTR>(new WCHAR[dwAcctName]);
DomainName = reinterpret_cast<LPWSTR>(new WCHAR[dwDomainName]);
if (!AcctName || !DomainName)
continue;
@ -289,6 +289,8 @@ int countProcs(const wstring user)
if (!wcscmp(AcctName, wuser))
++numProcs;
delete[] reinterpret_cast<LPWSTR>(AcctName);
delete[] reinterpret_cast<LPWSTR>(DomainName);
} while (Process32Next(hProcessSnap, &pe32));
@ -300,5 +302,7 @@ die:
CloseHandle(hProcess);
if (hToken)
CloseHandle(hToken);
if (pSIDTokenUser)
delete[] reinterpret_cast<PTOKEN_USER>(pSIDTokenUser);
return numProcs;
}

View File

@ -178,7 +178,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
&& GetLastError() != ERROR_MORE_DATA)
goto die;
lpServices = new BYTE[*pcbBytesNeeded];
lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
cbBufSize = *pcbBytesNeeded;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
@ -196,7 +196,7 @@ int ServiceStatus(const printInfoStruct& printInfo)
die:
if (lpServices)
delete lpServices;
delete[] reinterpret_cast<LPBYTE>(lpServices);
wcout << L"Service " << printInfo.service << L" could not be found" << endl;
return -1;
}