Skip to content

Latest commit

 

History

History
120 lines (92 loc) · 3.28 KB

nf-shlwapi-strdupw.md

File metadata and controls

120 lines (92 loc) · 3.28 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:shlwapi.StrDupW
StrDupW function (shlwapi.h)
Duplicates a string. (Unicode)
StrDup
StrDup function [Windows Shell]
StrDupW
_win32_StrDup
shell.StrDup
shlwapi/StrDup
shlwapi/StrDupW
shell\StrDup.htm
shell
fa77f0b3-8a9b-4221-87e3-9aebff4409fb
12/05/2018
StrDup, StrDup function [Windows Shell], StrDupA, StrDupW, _win32_StrDup, shell.StrDup, shlwapi/StrDup, shlwapi/StrDupA, shlwapi/StrDupW
shlwapi.h
Windows
Windows 2000 Professional, Windows XP [desktop apps only]
Windows 2000 Server [desktop apps only]
StrDupW (Unicode) and StrDupA (ANSI)
Shlwapi.lib
Shlwapi.dll (version 4.71 or later)
Windows
19H1
StrDupW
shlwapi/StrDupW
c++
APIRef
kbSyntax
DllExport
Shlwapi.dll
API-MS-Win-Core-shlwapi-Obsolete-l1-1-0.dll
KernelBase.dll
API-MS-Win-Core-shlwapi-Obsolete-l1-2-0.dll
API-MS-Win-DownLevel-shlwapi-l1-1-0.dll
API-MS-Win-DownLevel-shlwapi-l1-1-1.dll
StrDup
StrDupA
StrDupW

StrDupW function

-description

Duplicates a string.

-parameters

-param pszSrch

Type: PCTSTR

A pointer to a constant null-terminated character string.

-returns

Type: PTSTR

Returns the address of the string that was copied, or NULL if the string cannot be copied.

-remarks

StrDup will allocate storage the size of the original string. If storage allocation is successful, the original string is copied to the duplicate string.

This function uses LocalAlloc to allocate storage space for the copy of the string. The calling application must free this memory by calling the LocalFree function on the pointer returned by the call to StrDup.

Examples

This simple console application illustrates the use of StrDup.

#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>

void main(void)
{
   char buffer[] = "This is the buffer text";
   char *newstring;

   // Note: Never use an unbounded %s format specifier in printf.
   printf("Original: %25s\n", buffer);

   newstring = StrDup(buffer);
   if (newstring != NULL)
   {
       printf("Copy:     %25s\n", newstring);
       LocalFree(newstring);
   }
}

OUTPUT:
- - - - - - 
Original: This is the buffer text
Copy:     This is the buffer text

Note

The shlwapi.h header defines StrDup as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.