StrDupA function

Duplicates a string.

Syntax

PSTR StrDupA(
  PCSTR pszSrch
);

Parameters

pszSrch

Type: PCTSTR

A pointer to a constant null-terminated character string.

Return Value

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

Requirements

   
Minimum supported client Windows 2000 Professional, Windows XP [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header shlwapi.h
Library Shlwapi.lib
DLL Shlwapi.dll (version 4.71 or later)