'Format'에 해당되는 글 2건

  1. 2015.05.22 파일 크기 표시
  2. 2015.05.21 GetLastError() 에러코드를 문자열로 표시하기
카테고리 없음2015. 5. 22. 10:28

CString GetReadableFileSize(double fFileSizeInBytes) 

{

double size = fFileSizeInBytes;

int i = 0;

const TCHAR* units[] = {_T("Bytes"), _T("KB"), _T("MB"), _T("GB"), _T("TB"), _T("PB"), _T("EB"), _T("ZB"), _T("YB")};

while (size > 1024) 

{

size /= 1024;

i++;

}


CString strResult;

strResult.Format(_T("%.*f %s"), i, size, units[i]);

return strResult;

}


[원문 (Original Text) : HUMAN-READABLE FILE SIZE IN C]

Posted by 좋은나무
카테고리 없음2015. 5. 21. 10:47

LPVOID lpMsgBuf;

DWORD dwError = GetLastError(); 


FormatMessage(

FORMAT_MESSAGE_ALLOCATE_BUFFER | 

FORMAT_MESSAGE_FROM_SYSTEM |

FORMAT_MESSAGE_IGNORE_INSERTS,

NULL,

dwError,

MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

(LPTSTR) &lpMsgBuf,

0, NULL );


::OutputDebugString((LPCTSTR)lpMsgBuf);


LocalFree(lpMsgBuf);


[참고 : Retrieving the Last-Error Code]


Posted by 좋은나무