Export (0) Print
Expand All
4 out of 8 rated this helpful - Rate this topic

PathCombine function

Concatenates two strings that represent properly formed paths into one path; also concatenates any relative path elements.

Note  Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchCombine or PathCchCombineEx function in its place.

Syntax


LPTSTR PathCombine(
  _Out_     LPTSTR pszPathOut,
  _In_opt_  LPCTSTR pszPathIn,
  _In_      LPCTSTR pszMore
);

Parameters

pszPathOut [out]

Type: LPTSTR

A pointer to a buffer that, when this function returns successfully, receives the combined path string. You must set the size of this buffer to MAX_PATH to ensure that it is large enough to hold the returned string.

pszPathIn [in, optional]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the first path. This value can be NULL.

pszMore [in]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the second path. This value can be NULL.

Return value

Type: LPTSTR

A pointer to a buffer that, when this function returns successfully, receives the concatenated path string. This is the same string pointed to by pszPathOut. If this function does not return successfully, this value is NULL.

Remarks

The directory path should be in the form of A:,B:, ..., Z:. The file path should be in a correct form that represents the file name part of the path. If the directory path ends with a backslash, the backslash will be maintained. Note that while lpszDir and lpszFile are both optional parameters, they cannot both be NULL.

Examples


#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
// Buffer to hold combined path.
char buffer_1[MAX_PATH] = "";
char *lpStr1;
lpStr1 = buffer_1;

// String for balance of path name.
char buffer_2[ ] = "One\\Two\\Three";
char *lpStr2;
lpStr2 = buffer_2;

// String for directory name.
char buffer_3[ ] = "C:";
char *lpStr3;
lpStr3 = buffer_3;

cout << "The file path to be combined is  " 
     << lpStr2 << endl;
cout << "The directory name path is       " 
     << lpStr3 << endl;
cout << "The combined path is             " 
     << PathCombine(lpStr1,lpStr3,lpStr2) << endl;
}

------------
INPUT:
------------
Path for directory part: "C:"
Path for file part: "One\Two\Three"
------------
OUTPUT:
------------
The file path to be combined is  One\Two\Three
The directory name path is       C:
The combined path is             C:\One\Two\Three

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

PathCombineW (Unicode) and PathCombineA (ANSI)

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.