Here is my sample code:
PATA_PASS_THROUGH_DIRECT pATAPTD = NULL;
DWORD dataSize = sizeof(ATA_PASS_THROUGH_DIRECT) + 512;
pATAPTD = (PATA_PASS_THROUGH_DIRECT) VirtualAlloc(NULL, dataSize, MEM_COMMIT, PAGE_READWRITE);
ZeroMemory(pATAPTD, dataSize);
pATAPTD->Length = sizeof(ATA_PASS_THROUGH_DIRECT);
pATAPTD->DataBuffer = (PVOID)((char*)pATAPTD + sizeof(ATA_PASS_THROUGH_DIRECT));
pATAPTD->DataTransferLength = 512;
pATAPTD->TimeOutValue = 25;
pATAPTD->AtaFlags = 25;
unsigned short* pPassWrdBuffer = NULL;
pPassWrdBuffer = new unsigned short[256];
memset(pPassWrdBuffer,0,512);
pPassWrdBuffer[1]= Password;
char *pDataPtr = (char *)((char *)pATAPTD + sizeof(ATA_PASS_THROUGH_DIRECT));
memcpy_s((void *)( pDataPtr ), 512,
pPassWrdBuffer, 512);
pATAPTD->CurrentTaskFile[1] = 0x01;
pATAPTD->CurrentTaskFile[6] = 0xF1;
bResult = DeviceIoControl(m_hDisk,
IOCTL_ATA_PASS_THROUGH_DIRECT,
pATAPTD,
dataSize,/* input buffer and size */
pATAPTD,
dataSize,/* output buffer and size */
&BytesCopied,/* bytes copied to output buffer*/
NULL/* no overlapping */
);
This call fails only on windows 8 and windows server 2012 throwing message "The parameter is incorrect" (@err = 87). It works fine on windows 7. Can anyone provide some solution to this issue?