用VC写一段程序,得到当前操作系统所在的盘符?

解决方案 »

  1.   

    The GetSystemDirectory function retrieves the path of the system directory. The system directory contains such files as dynamic-link libraries, drivers, and font files. UINT GetSystemDirectory(
      LPTSTR lpBuffer,  // address of buffer for system directory
      UINT uSize        // size of directory buffer
    );
     
      

  2.   

    UINT GetSystemWindowsDirectory(
      LPTSTR lpBuffer,  // buffer to receive directory name
      UINT uSize        // size of name buffer
    );
      

  3.   

    char m_SysDir[128];
           GetSystemDirectory(m_SysDir,128);
      

  4.   

    int ch, drive, curdrive;
    static char path[_MAX_PATH];
    /* Save current drive. */
    curdrive = _getdrive();
    /* If we can switch to the drive, it exists. */
    for( drive = 1; drive <= 26; drive++ )
    {
    if( !_chdrive( drive ) )
    {
    char cMyDrive[_MAX_PATH];
    ch=drive + 'A' - 1;
    CString str;//str中保存盘符
    str.Format("%c",ch);
    }
    }
      

  5.   

    DWORD drives = GetLogicalDrives(); if (drives != 0)
    {
    CString str;
    CString driveDesc;
    char driveName[] = "A:\\";
    char driveLetter = 'A';
    long bits = 1;
    SHFILEINFO sfi;
    UINT flags = SHGFI_DISPLAYNAME;
    int size = sizeof(drives) * 8;
               for (int i=0; i<size; i++)
    {
    driveName[0] = driveLetter;
    driveDesc.Format("Drive (%c:)", driveLetter);
                 
    if (SHGetFileInfo(driveName, 0, &sfi, sizeof(sfi), flags))
    driveDesc = sfi.szDisplayName;
    if (drives & bits)
                               {
                                  ///this drive exist

    bits = bits << 1;
    driveLetter += 1;
                               }
    } }