黄江如何去深圳欢乐谷:GetEnvironmentVariable

来源:百度文库 编辑:高考问答 时间:2024/04/29 11:13:15
请问各位高手:当GetEnvironmentVariable函数的第2个参数是NULL,而第3个参数是0的时候,表示的是什么含义?我是在WINDOWS编程中发现此用法的.源函数如下GetEnvironmentVariable (pVarName, NULL, 0)
其中第1个参数的含义很明确,指的是某个环境变量的名字.

第2个参数 存放环境变量的值的单元(缓冲器)的地址
第3个参数 该单元的大小,以字符个数计.

DWORD GetEnvironmentVariable( LPCTSTR lpName,
// address of environment variable name

LPTSTR lpBuffer,
// address of buffer for variable value

DWORD nSize
// size of buffer, in characters

);

Parameters
lpName

Points to a null-terminated string that specifies the environment variable.

lpBuffer

Points to a buffer to receive the value of the specified environment variable.

nSize

Specifies the size, in characters, of the buffer pointed to by the lpBuffer parameter.

如果调用成功,该函数返回被查询环境变量的长度。
如果没有这个变量,返回零
如果缓冲区长度不够,返回***长度