Post

반응형
// 현재 위치 구하기
TCHAR filePath[_MAX_PATH]; // 현재 디렉토리
GetCurrentDirectory(_MAX_PATH, filePath);

string a = TCHARtoString(filePath);

printf("현재 디렉토리:%s", a.c_str());
			
const std::string TCHARtoString(const TCHAR* tcharStr) {
	int len = wcslen((wchar_t*)tcharStr);

	char resultStr[200]; //경로가 길므로 적당한 사이즈를 지정해준다
	size_t tcnt;

	wcstombs_s(&tcnt, resultStr, sizeof(resultStr), (wchar_t*)tcharStr, 2 * len + 1);

	return resultStr;
}

wcstombs_s 함수를 사용한다.

GetCurrentDirectory를 함수에서 TCHAR 형으로 현재 디렉토리 주소를 받아와서

어쩔 수 없이 TCHAR to String을 해야 했다.

근데 잘 안보이고ㅠㅠㅠ

고생고생하다가 겨우 찾았다ㅠㅠ

wcstombs_s 함수의 인자 출처:

https://learn.microsoft.com/ko-kr/cpp/c-runtime-library/reference/wcstombs-s-wcstombs-s-l?view=msvc-170

 

wcstombs_s, _wcstombs_s_l

자세한 정보: wcstombs_s, _wcstombs_s_l

learn.microsoft.com

 

 

반응형
▲ top