War diese Seite hilfreich?
Ihr Feedback ist uns wichtig. Teilen Sie uns Ihre Meinung mit.
Weiteres Feedback?
1500 verbleibende Zeichen
Exportieren (0) Drucken
Alle erweitern
div
eof
Erweitern Minimieren
Wichtig Dieses Dokument enthält ggf. nicht die bewährten Methoden für die aktuelle Entwicklung. Außerdem sind Links zu Downloads und anderen Ressourcen u. U. nicht mehr gültig. Die aktuell empfohlene Version finden Sie hier.

_dupenv_s_dbg, _wdupenv_s_dbg

Get a value from the current environment. Versions of _dupenv_s, _wdupenv_s that allocate memory with _malloc_dbg to provide additional debugging information.


errno_t _dupenv_s_dbg(
   char **buffer,
   size_t *sizeInBytes,
   const char *varname,
   int blockType,
   const char *filename,
   int linenumber
);
errno_t _wdupenv_s_dbg(
   wchar_t **buffer,
   size_t *sizeInWords,
   const wchar_t *varname,
   int blockType,
   const char *filename,
   int linenumber
);

Parameters

buffer

Buffer to store the variable's value.

sizeInBytes, sizeInWords

Size of buffer.

varname

Environment variable name.

blockType

Requested type of the memory block: _CLIENT_BLOCK or _NORMAL_BLOCK.

filename

Pointer to the name of the source file or NULL.

linenumber

Line number in source file or NULL.

Zero on success, an error code on failure.

These functions validate their parameters; if buffer or varname is NULL, the invalid parameter handler is invoked as described in Parameter Validation. If execution is allowed to continue, the functions set errno to EINVAL and return EINVAL.

If these functions cannot allocate enough memory, they set buffer to NULL and sizeinBytes (sizeInWords) to 0, and return ENOMEM.

The _dupenv_s_dbg and _wdupenv_s_dbg functions are identical to _dupenv_s and _wdupenv_s except that, when _DEBUG is defined, these functions use the debug version of malloc, _malloc_dbg, to allocate memory for the value of the environment variable. For information on the debugging features of _malloc_dbg, see _malloc_dbg.

You do not need to call these functions explicitly in most cases. Instead, you can define the flag _CRTDBG_MAP_ALLOC. When _CRTDBG_MAP_ALLOC is defined, calls to _dupenv_s and _wdupenv_s are remapped to _dupenv_s_dbg and _wdupenv_s_dbg, respectively, with the blockType set to _NORMAL_BLOCK. Thus, you do not need to call these functions explicitly unless you want to mark the heap blocks as _CLIENT_BLOCK. For more information on block types, see Types of Blocks on the Debug Heap.

Generic-Text Routine Mappings
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined

_tdupenv_s_dbg

_dupenv_s_dbg

_dupenv_s_dbg

_wdupenv_s_dbg

Routine Required header Compatibility

_dupenv_s_dbg

<crtdbg.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wdupenv_s_dbg

<crtdbg.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_dupenv_s_dbg.c
#include  <stdlib.h>
#include <crtdbg.h>

int main( void )
{
   char *pValue;
   size_t len;
   errno_t err = _dupenv_s_dbg( &pValue, &len, "pathext",
      _NORMAL_BLOCK, __FILE__, __LINE__ );
   if ( err ) return -1;
   printf( "pathext = %s\n", pValue );
   free( pValue );
   err = _dupenv_s_dbg( &pValue, &len, "nonexistentvariable",
      _NORMAL_BLOCK, __FILE__, __LINE__ );
   if ( err ) return -1;
   printf( "nonexistentvariable = %s\n", pValue );
   free( pValue ); // It's OK to call free with NULL
}

pathext = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.pl
nonexistentvariable = (null)
Anzeigen:
© 2015 Microsoft