인터넷/IT/프로그래밍

%SystemRoot% 와 같은 Expand 문자열을 실제 경로로 변경하는 코드

coffee94 2015. 6. 19. 07:16

std::wstring GetExpandEnvironmentStrings(const std::wstring& str)

{

WCHAR dstPath[MAX_PATH];

DWORD bufCharCount;

bufCharCount = ExpandEnvironmentStrings(str.c_str(), dstPath, MAX_PATH);

if (bufCharCount != 0 && bufCharCount <= MAX_PATH)

{

return dstPath;

}

else

{

return L"";

}

}


단순히 

GetExpandEnvironmentStrings(L"%SystemRoot%") 형태로 넘겨도 되고,

아래처럼 추가적인 경로가 포함되어 있어도 값을 리턴합니다.

GetExpandEnvironmentStrings(L"%SystemRoot%\\System32\\")