0

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?

  • 1
    Are you using two differently configured machines to test this, or are you carefully ensuring that the operating system is the *only* variable that is changing? Take note of the restrictions listed at the top of [the documentation](http://msdn.microsoft.com/en-us/library/windows/hardware/ff559315.aspx). – Cody Gray - on strike Mar 12 '13 at 11:12
  • Operating system is the only thing changing here. Hardware remains the same. – Manvendra Kumar Mar 13 '13 at 04:29

0 Answers0