Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
File Services
File Systems
Volume Management
 GetVolumePathNamesForVolumeName Fun...
GetVolumePathNamesForVolumeName Function

Retrieves a list of drive letters and volume GUID paths for the specified volume.

For more information about volume GUID paths, see Naming a File or Directory.

Syntax

C++
BOOL WINAPI GetVolumePathNamesForVolumeName(
  __in   LPCTSTR lpszVolumeName,
  __out  LPTSTR lpszVolumePathNames,
  __in   DWORD cchBufferLength,
  __out  PDWORD lpcchReturnLength
);

Parameters

lpszVolumeName [in]

A volume GUID path for the volume. A volume GUID path is of the form "\\?\Volume{GUID}\" where GUID is a GUID that identifies the volume.

lpszVolumePathNames [out]

A pointer to a buffer that receives the list of drive letters and volume GUID paths. The list is an array of null-terminated strings terminated by an additional NULL character. If the buffer is not large enough to hold the complete list, the buffer holds as much of the list as possible.

cchBufferLength [in]

The length of the lpszVolumePathNames buffer, in TCHARs, including all NULL characters.

lpcchReturnLength [out]

If the call is successful, this parameter is the number of TCHARs copied to the lpszVolumePathNames buffer. Otherwise, this parameter is the size of the buffer required to hold the complete list, in TCHARs.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. If the buffer is not large enough to hold the complete list, the error code is ERROR_MORE_DATA and the lpcchReturnLength parameter receives the required buffer size.

Examples

For an example, see Displaying Volume Paths.

Requirements

Minimum supported clientWindows XP
Minimum supported serverWindows Server 2003
HeaderWinBase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesGetVolumePathNamesForVolumeNameW (Unicode) and GetVolumePathNamesForVolumeNameA (ANSI)

See Also

Volume Management Functions
Mounted Folders

Send comments about this topic to Microsoft

Build date: 11/12/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Incorrect required buffer size for UNICODE version      ABOH   |   Edit   |   Show History

This function seems to have a bug when reporting the size of the required buffer. When I call it to determine the required buffer size, it reports that I need 5 bytes for the path name ("D:\" + NULL + NULL), which is correct. I allocate the buffer and make the call again. It succeeds and has the correct information in the buffer. When I try to free the buffer, I get a heap corrupted exception. I have not manipulated the buffer or pointer. In my example, if I allocate 10 bytes (2*requiredlength), everything is okay. If I allocate 9 bytes, it fails. This seems to indicate that the UNICODE version of this function is not returning the correct number of bytes, which would be ANSI size * 2. As a work-around, I am doubling the length it returns and all is well.


LPTSTR buf = NULL;
DWORD rlen = 0;
GetVolumePathNamesForVolumeNameW(volumeName, buf, 0, &rlen);
if (GetLastError() == ERROR_MORE_DATA)
{
buf = (LPTSTR) malloc (rlen*2);
.
.
.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker