这是我的示例代码:
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 */
);
此调用仅在 Windows 8 和 Windows Server 2012 上失败,并抛出消息“参数不正确”(@err = 87)。它在 Windows 7 上运行良好。任何人都可以为这个问题提供一些解决方案吗?