DeviceIoControl 返回错误码1,为什么?

rokia 2002-09-22 05:23:31
if(!DeviceIoControl(
hRootOfVolume,
IOCTL_CHANGER_GET_PRODUCT_DATA,
NULL,
0,
&product_data,
sizeof(product_data),
&returnsize,
NULL))

执行过后,用getlasterror()得到 1,(含义是功能错误)

为什么? 另外哪位大虾知道changer是什么意思?

这个问题搞了好长时间了。 我就是想得到一个volume对应的硬件是个什么东西。主要是针对移动存储,例如当用户插入一个数码相机的时候,我能知道新出来的盘符对应的是数码相机。

大恩不言谢,只有倾囊相赠了!!
...全文
1058 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rokia 2002-09-23
  • 打赏
  • 举报
回复
我用的XP。
wuxuan 2002-09-23
  • 打赏
  • 举报
回复
Windows 95/98/Me: Unsupported.
你使用的是什么操作系统?
rokia 2002-09-23
  • 打赏
  • 举报
回复
再來頂一下。

看來沒希望了。:(
wuxuan 2002-09-23
  • 打赏
  • 举报
回复
/* 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);
}
rokia 2002-09-22
  • 打赏
  • 举报
回复
你的SDK太舊了,升級一下就有了。

我的程序不但要知道它是 Removable,還想知道這是數碼相機。
oldworm 2002-09-22
  • 打赏
  • 举报
回复
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 类型。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧