Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Переменные окружения


Автор: SeregaLBN 3.3.2004, 12:01
Понадобилось узнать реальное значение переменной окружения %USERPROFILE%.
В SDK нашёл, вроде бы, подходящую ф-цию:

LPCTSTR FindEnvironmentString(LPCTSTR pszEnvVar);
Looks up the specified environment variable and returns a pointer to its value.
И написано, что обьявлена в <shellapi.h>.

Но у меня, в VC++ 6, в <shellapi.h> нет обьявления данной ф-ции.
Посмотрел в VC++ 5 - есть обьявление, но при линковке происходит ошибка - error LNK2001: unresolved external symbol.

Подскажите как можно по другому узнать занчения переменных окружения.

Автор: Borisff2003 3.3.2004, 13:54
А в моей shellapi есть только ето макрос с переключением для уникод
Поиши FindEnvironmentStringA и FindEnvironmentStringW
на них собственно макрос и перенапраляет

Автор: OlegsDP 3.3.2004, 16:23
В хелпе к Windows API я функции FindEnvironmentString не нашел. Но там есть вот что:

The GetEnvironmentVariable function retrieves the value of the specified variable from the environment block of the calling process. The value is in the form of a null-terminated string of characters.
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.

Return Values
If the function succeeds, the return value is the number of characters stored into the buffer pointed to by lpBuffer, not including the terminating null character.
If the specified environment variable name was not found in the environment block for the current process, the return value is zero.
If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in characters, required to hold the value string and its terminating null character.

Автор: Borisff2003 4.3.2004, 06:28
SeregaLBN
Существует и FindEnvironmentString и GetEnvironmentVariable

Автор: AlexNor 4.3.2004, 07:03
Вызови эту функцию -FindEnvironmentString- напрямую из shellapi.dll:
LoadLibrary(...)
GetProcAddr(...) ну и т.д.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)