Re: Application Crash with Error 5 when calling DeviceIOControl,...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You are also closing the handle twice..

"Kerem Gümrükcü" <kareem114@xxxxxxxxxxx> wrote in message
news:uSWNfFUdHHA.4216@xxxxxxxxxxxxxxxxxxxxxxx

"Kerem Gümrükcü" <kareem114@xxxxxxxxxxx> schrieb im Newsbeitrag
news:ODKS9OSdHHA.420@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

i have some code that must read the disk geometry for some
other functions. But whenever i call the code, i get a Application
crash and debugger say Error Code 5. But i dont know why this
happens. This Code is not the Final Code, but i "should" work, but
in fact it does not (psTargetString is a Pointer to a CString Object
and works fine, lpszPhysicalDrive is something like "C:" and also
works fine, handles are ok,...). The Crash comes when calling
the DeviceIOControl(...) not after, not before, right then:


HANDLE hStorageDevice = NULL;
TCHAR lpszPhysicalDrive[10];

ZeroMemory(lpszPhysicalDrive,sizeof(TCHAR)*10);
strcat(lpszPhysicalDrive,"\\\\.\\");
strcat(lpszPhysicalDrive,lpszDriveLetter);

DISK_GEOMETRY dg;
ZeroMemory(&dg,sizeof(dg));

psTargetString->Insert(psTargetString->GetLength(),"Drive Layout:\r\n");

hStorageDevice = CreateFile(lpszPhysicalDrive,0,FILE_SHARE_READ |
FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0, NULL);

if(hStorageDevice != INVALID_HANDLE_VALUE){


if(DeviceIoControl(hStorageDevice,
IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,&dg,sizeof(dg),NULL,NULL) ==
FALSE){


this->AppendLastError(psTargetString);

CloseHandle(hStorageDevice);

}else{


TCHAR lpszDGInfo[MAX_PATH];
ZeroMemory(lpszDGInfo,sizeof(TCHAR)*MAX_PATH);

wsprintf(lpszDGInfo,
"Bytes per Sector: %ul\r\n"
"Cylinders: %ul\r\n"
"Media Type(See Info above!): %ul\r\n"
"Sectors per Track: %ul\r\n"
"Tracks per Cylinder: %ul\r\n",
dg.BytesPerSector,
dg.Cylinders,
dg.MediaType,
dg.SectorsPerTrack,
dg.TracksPerCylinder);



psTargetString->Insert(psTargetString->GetLength(),lpszDGInfo);
}


}else{

this->AppendLastError(psTargetString);
}


CloseHandle(hStorageDevice);

Do you have any idea? Application ensures to run in administrative
privilleges,
before it even starts. Thanks in advance,...


Best regards

Kerem Gümrükcü



Hi,

ok i found it, it was the 6th Parameter for the DeviceIOControl, it had to
be a pointer to a DWORD, but i used a NULL, and of course this raised
an ACCESS_DENIED,....

Best regards

Kerem Gümrükcü






.



Relevant Pages

  • Re: Application Crash with Error 5 when calling DeviceIOControl,...
    ... crash and debugger say Error Code 5. ... HANDLE hStorageDevice = NULL; ... "Bytes per Sector: %ul\r\n" ... Best regards ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Application Crash with Error 5 when calling DeviceIOControl,...
    ... crash and debugger say Error Code 5. ... HANDLE hStorageDevice = NULL; ... "Bytes per Sector: %ul\r\n" ... Best regards ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Pressure gauge repair?
    ... > Does anyone know how to adjust mechanical pressure gauges? ... > fix one this morning and couldn't get the pointer to rest right at the ... I repeatedly moved the Bourdon tube carefully until the sector ran ... > slightly on either side of the peg. ...
    (rec.crafts.metalworking)
  • Re: Search Engines & Frames
    ... Many thanks for the pointer - it was something I had simply not previously ... menus on each page so you wouldnt necessarily *have* to see the graphic ... Ian Bull wrote: ... >Thank you & Regards ...
    (microsoft.public.frontpage.client)
  • RE: Screen capture
    ... To move the mouse pointer and simulate clicks you can use SendInput function ... > contains the main portion of the form. ... > Best regards ...
    (microsoft.public.dotnet.languages.csharp)