清除記憶卡問題XP/WIN7 |
尚未結案
|
jacky123xw2
一般會員 發表:1 回覆:1 積分:0 註冊:2016-05-12 發送簡訊給我 |
請教各位大大:以下的程式在XP系統執行沒問題,但在WIN7就無法寫空資料到記憶卡,WIN7UAC都是使用最低。難到XPWIN7語法要不同?麻煩幫忙voidTForm1::CF_CLEAR()//重置CF_CARD{DWORDnulldata;//discardresultsDISK_GEOMETRYpdg;ATA_PASS_THROUGH_EXapt;hDevice=CreateFile(szDevName[Dev_no],//drivetoopenGENERIC_READ|GENERIC_WRITE,//noaccesstothedriveFILE_SHARE_READ//sharemodeFILE_SHARE_WRITE,NULL,//defaultsecurityattributesOPEN_EXISTING,//disposition0,//fileattributesNULL);//donotcopyfileattributesif(hDevice==INVALID_HANDLE_VALUE){CloseHandle(hDevice);}if(hDevice!=INVALID_HANDLE_VALUE)//ifopenthedrive{bResult=DeviceIoControl(hDevice,//devicetobequeriedIOCTL_DISK_GET_DRIVE_GEOMETRY,//operationtoperformNULL,0,//noinputbuffer&pdg,sizeof(pdg),//outputbuffer&nulldata,//#bytesreturnedNULL);//synchronousI/Oif(bResult==1){for(inti=0;i<512;i ){buffer[i]=0xFF;}sector=1000;numsector=1;buffer[0]=0xAA;buffer[1]=0xBB;buffer[2]=0xCC;buffer[3]=0xDD;buffer[4]=0xE9;buffer[5]=0x03;buffer[6]=0x00;buffer[7]=0x00;buffer[8]=0xE9;buffer[9]=0x03;buffer[10]=0x00;buffer[11]=0x00;SetFilePointer(hDevice,(sector*512),NULL,FILE_BEGIN);if(!WriteFile(hDevice,buffer,512*numsector,&byteswrite,NULL)){MessageBox(0,"EraseCF_DeviceFailed!!","EraseError",MB_OK);//如果不可清除return;}else{MessageBox(0,"EraseCF_DeviceO.K","EraseData",MB_OK);}}}CloseHandle(hDevice);test=0;}
|
jacky123xw2
一般會員 發表:1 回覆:1 積分:0 註冊:2016-05-12 發送簡訊給我 |
[code cpp] void TForm1::CF_CLEAR() //重置CF_CARD(Clear all data) { DWORD nulldata; // discard results DISK_GEOMETRY pdg; ATA_PASS_THROUGH_EX apt; hDevice=CreateFile(szDevName[Dev_no], // drive to open GENERIC_READ|GENERIC_WRITE,//no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) { CloseHandle(hDevice); } if (hDevice != INVALID_HANDLE_VALUE) // if open the drive { //========= bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform NULL, 0, // no input buffer &pdg, sizeof(pdg), // output buffer &nulldata, // # bytes returned NULL); // synchronous I/O if(bResult==1) //如果可讀出GEOMETRY {// for(int i=0;i<512;i ){buffer[i]=0xFF;} sector=1000; numsector=1; buffer[0]=0xAA;buffer[1]=0xBB;buffer[2]=0xCC;buffer[3]=0xDD; buffer[4]=0xE9;buffer[5]=0x03;buffer[6]=0x00;buffer[7]=0x00; buffer[8]=0xE9;buffer[9]=0x03;buffer[10]=0x00;buffer[11]=0x00; SetFilePointer(hDevice,(sector*512),NULL,FILE_BEGIN); //bResult=WriteFile(hDevice,buffer,512*numsector,&bytesread,NULL); if(!WriteFile(hDevice,buffer,512*numsector,&byteswrite,NULL)) {//如果不可清除 MessageBox(0,"Erase CF_Device Failed !!","Erase Error",MB_OK); return; } else { MessageBox(0,"Erase CF_Device O.K ","Erase Data",MB_OK); } } } CloseHandle(hDevice); test=0; } [/code] |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |