从进程获取环境变量。 在非 Windows 平台上,运行时保留环境变量的内部缓存,以确保线程安全。 这意味着调用 getenv
不会读取启动后在进程中运行的托管代码设置的任何新的或更新的环境变量。
语法
HRESULT GetEnvironmentVariable(
[in, string] const WCHAR *szName,
[in] ULONG cchValue,
[out] ULONG *pcchValue,
[out, annotation("_Out_writes_to_(cchValue, *pcchValue)")]
WCHAR szValue[]);
参数
szName
[in]指向 null 终止的宽字符字符串的指针,其中包含要获取的环境变量的名称。
cchValue
[in]的长度(以字符 szValue
为单位)。
pcchValue
[out]指向总字符长度的 szValue
指针。
szValue
[out]调用方提供了宽字符缓冲区。 当函数返回缓冲区时,缓冲区将包含环境变量的值。
要求
平台: 请参阅 .NET 支持的作系统。
页眉: CorProf.idl、CorProf.h
.NET 版本: 自 .NET Core 3.1 起可用