- Joined
- Apr 29, 2007
- Messages
- 2
- Reaction score
- 0
/* Can anybody tell me what's the problem with the following code?
I am running it with the built-in Administrator account
and it's giving an ERROR 998
*/
#include <iostream>
using namespace std;
#ifndef WINVER
#define WINVER 0x0501
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#include "Winioctl.h"
int main()
{
HANDLE hPhysicalDrive = CreateFile(
"\\\\.\\PhysicalDrive0",
FILE_ALL_ACCESS,
FILE_SHARE_READ|FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
NULL);
if(hPhysicalDrive==INVALID_HANDLE_VALUE)
{
cout<<"Can\'t open device"<<endl;
return 0;
}
DWORD bytesRet;
DRIVE_LAYOUT_INFORMATION_EX* dlix = (DRIVE_LAYOUT_INFORMATION_EX*)malloc(5120);//Just to ensure enough space
if(dlix==NULL)
{
cout<<"Memory Allocation failed"<<endl;
CloseHandle(hPhysicalDrive);
return 0;
}
BOOL ioctlSucceed = DeviceIoControl(
hPhysicalDrive,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL,
0,
(LPVOID)&dlix,
5120,
(LPDWORD)&bytesRet,
NULL);
if(ioctlSucceed)
{
cout<<"Success"<<endl;
cout<<"Number of partitions: "<<dlix->PartitionCount<<endl;
switch(dlix->PartitionStyle)
{
case 0://MBR
cout<<"Partition style is MBR"<<endl;
cout<<"Signature in hex: "<<hex<<uppercase<<dlix->Mbr.Signature<<endl;
break;
case 1://GPT
cout<<"Partition style is GPT"<<endl;
break;
case 2://RAW
cout<<"Partition style is RAW"<<endl;
break;
}
}
else
{
cout<<"DeviceIoControl failed with error: "<<GetLastError()<<endl;
//Output: DeviceIoControl failed with error: 998
}
free((void*)dlix);
CloseHandle(hPhysicalDrive);
return 0;
}
I am running it with the built-in Administrator account
and it's giving an ERROR 998
*/
#include <iostream>
using namespace std;
#ifndef WINVER
#define WINVER 0x0501
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#include "Winioctl.h"
int main()
{
HANDLE hPhysicalDrive = CreateFile(
"\\\\.\\PhysicalDrive0",
FILE_ALL_ACCESS,
FILE_SHARE_READ|FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
NULL);
if(hPhysicalDrive==INVALID_HANDLE_VALUE)
{
cout<<"Can\'t open device"<<endl;
return 0;
}
DWORD bytesRet;
DRIVE_LAYOUT_INFORMATION_EX* dlix = (DRIVE_LAYOUT_INFORMATION_EX*)malloc(5120);//Just to ensure enough space
if(dlix==NULL)
{
cout<<"Memory Allocation failed"<<endl;
CloseHandle(hPhysicalDrive);
return 0;
}
BOOL ioctlSucceed = DeviceIoControl(
hPhysicalDrive,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL,
0,
(LPVOID)&dlix,
5120,
(LPDWORD)&bytesRet,
NULL);
if(ioctlSucceed)
{
cout<<"Success"<<endl;
cout<<"Number of partitions: "<<dlix->PartitionCount<<endl;
switch(dlix->PartitionStyle)
{
case 0://MBR
cout<<"Partition style is MBR"<<endl;
cout<<"Signature in hex: "<<hex<<uppercase<<dlix->Mbr.Signature<<endl;
break;
case 1://GPT
cout<<"Partition style is GPT"<<endl;
break;
case 2://RAW
cout<<"Partition style is RAW"<<endl;
break;
}
}
else
{
cout<<"DeviceIoControl failed with error: "<<GetLastError()<<endl;
//Output: DeviceIoControl failed with error: 998
}
free((void*)dlix);
CloseHandle(hPhysicalDrive);
return 0;
}
Last edited: