home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / util2.cpp < prev    next >
C/C++ Source or Header  |  2008-07-13  |  1KB  |  50 lines

  1. /* util2.cpp */
  2.  
  3. #if defined(WIN32) || defined(_WINDOWS)
  4. #    define _CRT_SECURE_NO_WARNINGS 1
  5. #    pragma warning(disable : 4510)    // warning C4510: 'DStr' : default constructor could not be generated
  6. #    pragma warning(disable : 4512)    // warning C4512: 'DStr' : assignment operator could not be generated
  7. #    pragma warning(disable : 4610)    // warning C4610: struct 'DStr' can never be instantiated - user defined constructor required
  8. //#    include "syshdrs.h"
  9. #    ifndef WINVER
  10. #        define WINVER 0x0400
  11. #    endif
  12. #    ifndef _WIN32_WINNT
  13. #        define _WIN32_WINNT 0x0400
  14. #    endif
  15. #    include <windows.h>        /* includes <winsock2.h> if _WIN32_WINNT >= 0x400 */
  16. #    include <shlobj.h>
  17. #    include <process.h>
  18.  
  19. extern "C" void
  20. GetSpecialDir(char *dst, size_t size, int whichDir)
  21. {
  22.     LPITEMIDLIST idl;
  23.     LPMALLOC shl;
  24.     char path[MAX_PATH + 1];
  25.     HRESULT hResult;
  26.     
  27.     memset(dst, 0, size);
  28.     hResult = SHGetMalloc(&shl);
  29.     if (SUCCEEDED(hResult)) {
  30.         hResult = SHGetSpecialFolderLocation(
  31.                     NULL,
  32.                     whichDir,
  33.                     &idl
  34.                     );
  35.  
  36.         if (SUCCEEDED(hResult)) {
  37.             if(SHGetPathFromIDList(idl, path)) {
  38.                 (void) strncpy(dst, path, size - 1);
  39.                 dst[size - 1] = '\0';
  40.             }
  41.             shl->Free(idl);
  42.         }
  43.         shl->Release();
  44.     }
  45. }    // GetSpecialDir
  46.  
  47.  
  48. #endif
  49.  
  50.