Category: C++

Getting an environment variable

_dupenv_s will return a pointer to an allocated buffer that contains the value of the environment variable, which makes the most basic usage form: char* buffer; size_t bsize; _dupenv_s(&buffer, &bsize, “USERDOMAIN”); printf(buffer); free(buffer); The function is capable to return an error code if something goes horribly wrong. Note that a “not found” condition is NOT considered an error, and should be detected by buffer being NULL or the size of the buffer which will also […]