Thanks man for the example but can you please convert the sample code into conditional operator version one?.
Having difficulties to understand it without comparing both of them.
Also just notice in the example the end has only 2 parameters :
Code:
intresult = (choice ? add : sub)(1, 2);
While in mine it has 3? parameters :
Code:
bResult = (lpOverlapped->dwCommand == FILE_READ ? ReadFile : WriteFile)(lpOverlapped->hFile->FileHandle, lpOverlapped->lpBuffer, lpOverlapped->dwBuffer, &dwResult, (LPOVERLAPPED)lpOverlapped);
About FILE_READ :
Code:
#define FILE_READ 0
#define FILE_WRITE 1
After re-reading, starting to understand it, current conversion :
Code:
if (lpOverlapped)
{
if (lpOverlapped->dwCommand == FILE_READ)
{
bResult = WriteFile(lpOverlapped->hFile->FileHandle,
lpOverlapped->lpBuffer, lpOverlapped->dwBuffer, &dwResult, (LPOVERLAPPED)lpOverlapped);
}
else
{
bResult = ReadFile(lpOverlapped->hFile->FileHandle,
lpOverlapped->lpBuffer, lpOverlapped->dwBuffer, &dwResult, (LPOVERLAPPED)lpOverlapped);
}
if (!bResult && (dwResult = GetLastError()) != ERROR_IO_PENDING)
{
lpOverlapped->Internal = dwResult;
PostQueuedCompletionStatus(hCompletionPort, 0, (DWORD)-5, (LPOVERLAPPED)lpOverlapped);
}
}
What do you think?, what have i did wrong this time?.