PathCchRenameExtension function (pathcch.h)

Replaces a file name's extension at the end of a path string with a new extension. If the path string does not end with an extension, the new extension is added.

This function differs from PathRenameExtension in that it accepts paths with "\", "\?" and "\?\UNC" prefixes.

Note  This function should be used in place of PathRenameExtension to prevent the possibility of a buffer overrun.

Syntax

WINPATHCCHAPI HRESULT PathCchRenameExtension(
  [in, out] PWSTR  pszPath,
  [in]      size_t cchPath,
  [in]      PCWSTR pszExt
);

Parameters

[in, out] pszPath

A pointer to the path string. When this function returns successfully, this value points to the same string, but with the renamed or added extension.

[in] cchPath

The size of the buffer pointed to by pszPath, in characters.

[in] pszExt

A pointer to the new extension string. The leading '.' character is optional. In the case of an empty string (""), any existing extension in the path string is removed.

Return value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Requirements

Requirement Value
Minimum supported client Windows 8 [desktop apps | UWP apps]
Minimum supported server Windows Server 2012 [desktop apps | UWP apps]
Target Platform Windows
Header pathcch.h
Library Pathcch.lib