Re: Application Crash with Error 5 when calling DeviceIOControl,...
- From: "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx>
- Date: Mon, 2 Apr 2007 12:53:00 -0700
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ü
.
- Follow-Ups:
- Re: Application Crash with Error 5 when calling DeviceIOControl,...
- From: Kerem Gümrükcü
- Re: Application Crash with Error 5 when calling DeviceIOControl,...
- References:
- Application Crash with Error 5 when calling DeviceIOControl,...
- From: Kerem Gümrükcü
- Re: Application Crash with Error 5 when calling DeviceIOControl,...
- From: Kerem Gümrükcü
- Application Crash with Error 5 when calling DeviceIOControl,...
- Prev by Date: Re: How to fix windows explorer's virtual memory size?
- Next by Date: Re: Application Crash with Error 5 when calling DeviceIOControl,...
- Previous by thread: Re: Application Crash with Error 5 when calling DeviceIOControl,...
- Next by thread: Re: Application Crash with Error 5 when calling DeviceIOControl,...
- Index(es):
Relevant Pages
|