GetVolumeNameForVolumeMountPoint 返回 false
为了获取卷 GUID,我尝试了如下代码,
int len = wcslen( pDetData->DevicePath);
pDetData->DevicePath[len] = '\\';
pDetData->DevicePath[len+1] = 0;
#define BUFFER_SIZE MAX_PATH
WCHAR volume[BUFFER_SIZE];
BOOL bFlag;
bFlag = GetVolumeNameForVolumeMountPoint( pDetData->DevicePath, volume, BUFFER_SIZE );
int loginErrCode = GetLastError();
printf("loginErrCode: %d\n", loginErrCode);
printf("BFLAG: %d\n", bFlag);
GetLastError() 也将其打印为 1 。这意味着 ERROR_INVALID_FUNCTION。 bFlag 总是返回零,这意味着 false。
我的代码有什么问题...
To get the volume GUID i tried the code like below
int len = wcslen( pDetData->DevicePath);
pDetData->DevicePath[len] = '\\';
pDetData->DevicePath[len+1] = 0;
#define BUFFER_SIZE MAX_PATH
WCHAR volume[BUFFER_SIZE];
BOOL bFlag;
bFlag = GetVolumeNameForVolumeMountPoint( pDetData->DevicePath, volume, BUFFER_SIZE );
int loginErrCode = GetLastError();
printf("loginErrCode: %d\n", loginErrCode);
printf("BFLAG: %d\n", bFlag);
the GetLastError() also prints it as 1 . it means ERROR_INVALID_FUNCTION. The bFlag always returns zero it means false.
what is the problem in my code...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这需要一些水晶球咨询。 DevicePath 字符串看起来像是来自 SP_DEVICE_INTERFACE_DETAIL_DATA。这是一个不属于您的字符串,修改它最多会损坏内部 setupapi 数据库,最坏的情况会损坏堆。在将字符串转换为根目录名称之前,您必须将字符串复制到自己的缓冲区中。
这只是一个理论,尤其是“loginErrCode”对于代码的作用来说是一个非常奇怪的名称。验证您最终得到的字符串至少看起来类似于“F:\”。
This requires some crystal-ball consulting. The DevicePath string looks like it comes from SP_DEVICE_INTERFACE_DETAIL_DATA. That's a string that you don't own, modifying it corrupts the internal setupapi database at best, the heap at worst. You'll have to copy the string into your own buffer before turning it into the root directory name.
This is just a theory, especially "loginErrCode" is a very strange name for what the code seems to do. Verify that the string you end up with at least looks similar to "F:\".