PathAddBackslash function
Adds a backslash to the end of a string to create the correct syntax for a path. If the source path already has a trailing backslash, no backslash will be added.
Syntax
LPTSTR PathAddBackslash( _Inout_ LPTSTR lpszPath );
Parameters
- lpszPath [in, out]
-
Type: LPTSTR
A pointer to a buffer with a string that represents a path. The size of this buffer must be set to MAX_PATH to ensure that it is large enough to hold the returned string.
Return value
Type: LPTSTR
A pointer that, when this function returns successfully, points to the new string's terminating null character. If the backslash could not be appended due to inadequate buffer size, this value is NULL.
Examples
#include <windows.h> #include <iostream.h> #include "Shlwapi.h" void main( void ) { // String for path name without backslash. char buffer_1[MAX_PATH] = "C:\\dir_name\\dir_name\\file_name"; char *lpStr1; lpStr1 = buffer_1; // String for path name with backslash. char buffer_2[MAX_PATH] = "C:\\dir_name\\dir_name\\file_name\\"; char *lpStr2; lpStr2 = buffer_2; cout << "The original path string 1 is " << lpStr1 << endl; cout << "The modified path string 1 is " << PathAddBackslash(lpStr1) << lpStr1 << endl; cout << "\nThe original path string 2 is " << lpStr2 << endl; cout << "The modified path string 2 is " << PathAddBackslash(lpStr2) << lpStr2 << endl; } OUTPUT: --------- The original path string 1 is C:\dir_name\dir_name\file_name The modified path string 1 is C:\dir_name\dir_name\file_name\ The original path string 2 is C:\dir_name\dir_name\file_name\ The modified path string 2 is C:\dir_name\dir_name\file_name\
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 |
PathAddBackslashW (Unicode) and PathAddBackslashA (ANSI) |