PathGetDriveNumber function
Searches a path for a drive letter within the range of 'A' to 'Z' and returns the corresponding drive number.
Syntax
int PathGetDriveNumber(
_In_ LPCTSTR lpsz
);
Parameters
- lpsz [in]
-
Type: LPCTSTR
A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be searched.
Return value
Type: int
Returns 0 through 25 (corresponding to 'A' through 'Z') if the path has a drive letter, or -1 otherwise.
Examples
#include <windows.h> #include <iostream.h> #include "Shlwapi.h" void main( void ) { // Paths to search for drive IDs. char buffer_1[ ] = "A:\\TEST\\bar.txt"; char *lpStr1; lpStr1 = buffer_1; char buffer_2[ ] = "B:\\TEST\\bar.txt"; char *lpStr2; lpStr2 = buffer_2; char buffer_3[ ] = "Z:\\TEST\\bar.txt"; char *lpStr3; lpStr3 = buffer_3; char buffer_4[ ] = "%:\\TEST\\bar.txt"; char *lpStr4; lpStr4 = buffer_4; cout << "The path passed to the function was : " << lpStr1 << "\nThe path contains a drive identifier : " << PathGetDriveNumber(lpStr1) << endl; cout << "The path passed to the function was : " << lpStr2 << "\nThe path contains a drive identifier : " << PathGetDriveNumber(lpStr2) << endl; cout << "The path passed to the function was : " << lpStr3 << "\nThe path contains a drive identifier : " << PathGetDriveNumber(lpStr3) << endl; cout << "The path passed to the function was : " << lpStr4 << "\nThe path contains a drive identifier : " << PathGetDriveNumber(lpStr4) << endl; } OUTPUT: =========== The path passed to the function was : A:\TEST\bar.txt The path contains a drive identifier : 0 The path passed to the function was : B:\TEST\bar.txt The path contains a drive identifier : 1 The path passed to the function was : Z:\TEST\bar.txt The path contains a drive identifier : 25 The path passed to the function was : %:\TEST\bar.txt The path contains a drive identifier : -1
Requirements
|
Minimum supported client |
Windows 2000 Professional, Windows XP [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows 2000 Server [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names |
PathGetDriveNumberW (Unicode) and PathGetDriveNumberA (ANSI) |