컴쟁이의 연구실/코드조각

CTempBuffer 사용 예시

0range Blog 2022. 7. 10. 00:32

CTempBuffer 라는게 있어서, 검색했지만 설명이

많지가 않았다.

 

참고: https://github.com/microsoft/VCSamples/blob/master/VC2010Samples/MFC/internet/DHtmlExplore/DHtmlExploreDlg.cpp

CTempBuffer<TCHAR, MAX_PATH> strBuffer(MAX_PATH);
strBuffer[0] = _T('\0');
DWORD length = GetCurrentDirectory(MAX_PATH, strBuffer);

if (length > MAX_PATH)
{
  // We need to reallocate the string => MAX_PATH wasn't space enough.
  strBuffer.Reallocate(length);
  strBuffer[0] = _T('\0');
  GetCurrentDirectory(length, strBuffer);
}