DeviceIoControl 返回错误码1,为什么?
if(!DeviceIoControl(
hRootOfVolume,
IOCTL_CHANGER_GET_PRODUCT_DATA,
NULL,
0,
&product_data,
sizeof(product_data),
&returnsize,
NULL))
执行过后,用getlasterror()得到 1,(含义是功能错误)
为什么? 另外哪位大虾知道changer是什么意思?
这个问题搞了好长时间了。 我就是想得到一个volume对应的硬件是个什么东西。主要是针对移动存储,例如当用户插入一个数码相机的时候,我能知道新出来的盘符对应的是数码相机。
大恩不言谢,只有倾囊相赠了!!
问题点数:100、回复次数:6Top
1 楼oldworm(oldworm)回复于 2002-09-22 17:29:53 得分 50
DeviceIoControl第二个参数好像没有
IOCTL_CHANGER_GET_PRODUCT_DATA 这么个值
你这里搞错了,所以出现功能错误(根本不支持这个功能嘛)
你可以用
UINT GetDriveType(
LPCTSTR lpRootPathName // root directory
);
得到对应盘是什么类型,返回类型有下面这些:
DRIVE_UNKNOWN The drive type cannot be determined.
DRIVE_NO_ROOT_DIR The root path is invalid. For example, no volume is mounted at the path.
DRIVE_REMOVABLE The disk can be removed from the drive.
DRIVE_FIXED The disk cannot be removed from the drive.
DRIVE_REMOTE The drive is a remote (network) drive.
DRIVE_CDROM The drive is a CD-ROM drive.
DRIVE_RAMDISK The drive is a RAM disk.
你的数码相机大概是属于DRIVE_REMOVABLE 类型。
Top
2 楼rokia(■大力水手■)回复于 2002-09-22 17:47:07 得分 0
你的SDK太舊了,升級一下就有了。
我的程序不但要知道它是 Removable,還想知道這是數碼相機。Top
3 楼rokia(■大力水手■)回复于 2002-09-23 09:07:26 得分 0
再來頂一下。
看來沒希望了。:(Top
4 楼wuxuan(真心英雄)回复于 2002-09-23 09:30:50 得分 0
Windows 95/98/Me: Unsupported.
你使用的是什么操作系统?Top
5 楼rokia(■大力水手■)回复于 2002-09-23 11:52:17 得分 0
我用的XP。
Top
6 楼wuxuan(真心英雄)回复于 2002-09-23 13:40:46 得分 50
/* The code of interest is in the subroutine GetDriveGeometry. The
code in main shows how to interpret the results of the IOCTL call. */
#include <windows.h>
#include <winioctl.h>
BOOL
GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
hDevice = CreateFile("\\\\.\\PhysicalDrive0", // drive to open
0, // don't need any access to the drive
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // don't copy any file's attributes
if (hDevice == INVALID_HANDLE_VALUE) // we can't open the drive
{
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device we are querying
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer, so pass zero
pdg, sizeof(*pdg), // output buffer
&junk, // discard count of bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
CloseHandle(hDevice); // we're done with the handle
return (bResult);
}
int
main(int argc, char *argv[])
{
DISK_GEOMETRY pdg; // disk drive geometry structure
BOOL bResult; // generic results flag
ULONGLONG DiskSize; // size of the drive, in bytes
bResult = GetDriveGeometry (&pdg);
if (bResult)
{
printf("Cylinders = %I64d\n", pdg.Cylinders);
printf("Tracks per cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
printf("Sectors per track = %ld\n", (ULONG) pdg.SectorsPerTrack);
printf("Bytes per sector = %ld\n", (ULONG) pdg.BytesPerSector);
DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Mb)\n", DiskSize,
DiskSize / (1024 * 1024));
} else {
printf ("Attempt to get drive geometry failed. Error %ld.\n",
GetLastError ());
}
return ((int)bResult);
}
Top
相关问题
- 为什么QueryInterFace总是返回错误码0x80070057?
- 为什么GetlastError取不到错误码?
- CoCreateInstance返回的错误码为800401F0是代表什么错误?
- DhcpNotifyConfigChange这个函数总是返回错误码啊!
- 怎么把err.LastDllError返回的错误码转成字符串信息?
- oracle 错误码2134
- 在VB中如何得到SQL SERVER返回的错误码(类似C中的sqlca.sqlcode的东西)?
- 关于http请求的问题,如何得到返回的错误码,比如404?
- 2000里 事件查看器里 不能收集到 FTP 性能统计资料。 服务返回的错误码是数据
- 用VB6操作WORD文档,关闭后再次打开系统会返回错误码462。请问这个问题应该怎么解决?




