- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下代码,它应该获取外部驱动器的句柄并获取扇区大小。
HANDLE hRawDisk = CreateFile(L"\\\\.\\F:",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING,
NULL);
if (hRawDisk == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed\r\n");
PrintLastError();
return -1;
}
DWORD sectorsPerCluster;
DWORD bytesPerSector;
DWORD numberOfFreeClusters;
DWORD totalNumberOfClusters;
if (!GetDiskFreeSpace(L"\\\\.\\F:", §orsPerCluster, &bytesPerSector,
&numberOfFreeClusters, &totalNumberOfClusters))
{
printf("GetDiskFreeSpace failed\r\n");
PrintLastError();
CloseHandle(hRawDisk);
return -2;
}
我不知道为什么函数 GetDiskFreeSpace 返回 ERROR_INVALID_FUNCTION。它可能与访问权限有关吗?
使用函数 GetDiskFreeSpaceEx 给出完全相同的结果。
最佳答案
引用函数 GetDiskFreeSpace
的 MSDN 文档,关于第一个参数(https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx):
The root directory of the disk for which information is to be returned. If this parameter is NULL, the function uses the root of the current disk. If this parameter is a UNC name, it must include a trailing backslash (for example, "\MyServer\MyShare\"). Furthermore, a drive specification must have a trailing backslash (for example, "C:\"). The calling application must have FILE_LIST_DIRECTORY access rights for this directory.
因此,例如,您可以按以下方式调用该函数:
GetDiskFreeSpace(L"F:\\", §orsPerCluster, &bytesPerSector,
&numberOfFreeClusters, &totalNumberOfClusters)
关于c - GetDiskFreeSpace 函数返回 ERROR_INVALID_FUNCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31683764/
我正在编写一个需要创建/删除注册表项的程序。我遇到的问题是创建 key 的代码返回 ERROR_INVALID_FUNCTION . 如果您查看注册表,则已创建 key ,因此我不确定此错误的影响是什
我有以下代码,它应该获取外部驱动器的句柄并获取扇区大小。 HANDLE hRawDisk = CreateFile(L"\\\\.\\F:",
我尝试打开设备对象并通过 CreateFile 和 DeviceIoControl 向我的驱动程序发送请求,但是 CreateFile 失败并显示 ERROR_INVALID_FUNCTION,如果我
我是一名优秀的程序员,十分优秀!