Program 2-6 implements a version of the UNIX command pwd. The MAX_PATH value is used to size the buffer, but an error test is still included to illustrate GetCurrentDirectory.
/* Chapter 2. pwd -- Print working directory. */ #include "EvryThng.h" #define DIRNAME_LEN MAX_PATH + 2 int _tmain (int argc, LPTSTR argv []) { TCHAR pwdBuffer [DIRNAME_LEN]; DWORD LenCurDir; LenCurDir = GetCurrentDirectory (DIRNAME_LEN, pwdBuffer); if (LenCurDir == 0) ReportError (_T ("Failure getting pathname."), 1, TRUE); if (LenCurDir > DIRNAME_LEN) ReportError (_T ("Pathname is too long."), 2, FALSE); PrintMsg (GetStdHandle (STD_OUTPUT_HANDLE), pwdBuffer); return 0; }