I have a COM component for managing disk related tasks. While getting some disk information criteria, I have one or more source drives and one destination drive. When I retrieve the source drive name, COM gives me something like {e42c3d59-e32c-11e1-9aa5-806e6f6e6963}. How can I dereference this into a volume name?

有帮助吗?

解决方案

This really depends on what you mean by "volume name". If you mean the actual name of the volume you can create it based on the string representation of the GUID returned by the COM object. The volume name is in the form of \\?\Volume{GUID} where GUID is the identifier of the volume.

If you mean the volume label you can retrieve it by calling GetVolumeInformation() using the volume name described above.

// Just so we have something a bit clearer than calling a member function
// of the COM object.
const std::wstring& volumeGuid = L"{e42c3d59-e32c-11e1-9aa5-806e6f6e6963}";

// We have the GUID now get the volume label
std::wstring volumeName = L"\\\\?\\Volume" + volumeGuid + L"\\";
std::wstring::value_type volumeLabelBuffer[MAX_PATH];

BOOL result = ::GetVolumeInformation(
    volumeName.c_str(),
    volumeLabelBuffer,
    sizeof(volumeLabelBuffer) / sizeof(volumeLabelBuffer[0]),
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    0);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top