none
Немогу понять почему "вектор" оказывается пустым RRS feed

  • Вопрос

  • Вот сам код

    struct Speed//
    
    {
    
      float visible;//
    
      long real;//
    
    };
    
    struct DiskInfo//
    
    {
    
      std::string media;//
    
      __int64 fresz;//
    
      __int64 totalsz;//
    
      std::vector<Speed> speeds;//
    
    };
    
    void GetDiskInfo(std::string driveId,DiskInfo &info)
    
      {
    
        IDiscFormat2Data *FD;
    
        long totalsectors=0,freesectors=0;
    
        __int64 totalsize=0,freesize=0;
    
        IDiscRecorder2 *discRecorder;
    
        IMAPI_MEDIA_PHYSICAL_TYPE media;
    
        std::string mt="";
    
        for(;;)
    
        {
    
          hr = CoCreateInstance(__uuidof(MsftDiscRecorder2),NULL,CLSCTX_INPROC_SERVER,__uuidof(IDiscRecorder2),(void**)&discRecorder);
    
       if(hr==S_OK | hr!=0x8001010D){break;}
    
        }
    
        ErrorInfo(hr,"CoCreateInstance:IDiscRecorder2");
    
        hr = CoCreateInstance(__uuidof(MsftDiscFormat2Data) ,NULL,CLSCTX_INPROC_SERVER,__uuidof(IDiscFormat2Data),(void**)&FD);
    
        ErrorInfo(hr,"CoCreateInstance:IDiscFormat2Data");
    
        BSTR drvid;
    
        StrToBSTR(drvid,driveId);
    
        hr=discRecorder->InitializeDiscRecorder(drvid);
    
        ErrorInfo(hr,"IDiscRecorder2:InitializeDiscRecorder");
    
        BSTR cln;
    
        StrToBSTR(cln,std::string(ClientName));
    
      hr=discRecorder->AcquireExclusiveAccess(false,cln);
    
        ErrorInfo(hr,"IDiscRecorder2:AcquireExclusiveAccess");
    
        FD->put_Recorder(discRecorder);
    
        hr=FD->get_CurrentPhysicalMediaType(&media);
    
        //ErrorInfo(hr,"!!!!");
    
        if(hr==S_OK)
    
        {
    
          switch(media)
    
          {
    
            case IMAPI_MEDIA_TYPE_UNKNOWN:{mt="UNKNOWN";}break;
    
            case IMAPI_MEDIA_TYPE_CDROM:{mt="CD-ROM";}break;
    
            case IMAPI_MEDIA_TYPE_CDR:{mt="CD-R";}break;
    
            case IMAPI_MEDIA_TYPE_CDRW:{mt="CD-RW";}break;
    
            case IMAPI_MEDIA_TYPE_DVDROM:{mt="DVD-ROM";}break;
    
            case IMAPI_MEDIA_TYPE_DVDRAM:{mt="DVD-RAM";}break;
    
            case IMAPI_MEDIA_TYPE_DVDPLUSR:{mt="DVD+R";}break;
    
            case IMAPI_MEDIA_TYPE_DVDPLUSRW:{mt="DVD+RW";}break;
    
            case IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:{mt="DVD+R DL";}break;
    
            case IMAPI_MEDIA_TYPE_DVDDASHR:{mt="DVD-R";}break;
    
            case IMAPI_MEDIA_TYPE_DVDDASHRW:{mt="DVD-RW";}break;
    
            case IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:{mt="DVD-R DL";}break;
    
            case IMAPI_MEDIA_TYPE_DISK:{mt="IMAPI_MEDIA_TYPE_DISK";}break;
    
            case IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:{mt="DVD+RW DL";}break;
    
            case IMAPI_MEDIA_TYPE_HDDVDROM:{mt="HD-DVD-ROM";}break;
    
            case IMAPI_MEDIA_TYPE_HDDVDR:{mt="HD-DVD-R";}break;
    
            case IMAPI_MEDIA_TYPE_HDDVDRAM:{mt="HD-DVD-RAM";}break;
    
            case IMAPI_MEDIA_TYPE_BDROM:{mt="BD-ROM";}break;
    
            case IMAPI_MEDIA_TYPE_BDR:{mt="BD-R";}break;
    
            case IMAPI_MEDIA_TYPE_BDRE:{mt="BD-RE";}break;
    
       }
    
          if(media!=0x1 && media!=0x4 && media!=0xc && media!=0xe && media!=0x12 && media!=0x13)
    
          {
    
            hr=FD->get_TotalSectorsOnMedia(&totalsectors);
    
            ErrorInfo(hr,"get_TotalSectorsOnMedia");
    
            hr=FD->get_FreeSectorsOnMedia(&freesectors);
    
            ErrorInfo(hr,"get_FreeSectorsOnMedia");
    
            totalsize=totalsectors*2048;
    
            freesize=freesectors*2048;
    
            VARIANT_BOOL blank;
    
            FD->get_MediaHeuristicallyBlank(&blank);
    
            if(blank==VARIANT_TRUE)
    
            {
    
            SAFEARRAY *ss;
    
            VARIANT *varar;
    
            hr=FD->get_SupportedWriteSpeeds(&ss);
    
            ErrorInfo(hr,"FD->get_SupportedWriteSpeeds");
    
            if(hr==S_OK)
    
            {
    
              SafeArrayAccessData(ss,(void**)&varar);
    
              std::vector<Speed> sp;
    
              Speed spd;
    
              ULONG totalWriteSpeeds = (ULONG)ss->rgsabound[0].cElements;
    
              for (ULONG writeSpeedIndex = 0; writeSpeedIndex < totalWriteSpeeds; writeSpeedIndex++)
    
              {
    
                ULONG sectorsPerSecond = varar[writeSpeedIndex].ulVal;
    
                if(media==0x2 | media==0x3)
    
                {
    
                  spd.real=sectorsPerSecond;
    
                  spd.visible=rotateCD(sectorsPerSecond);
    
                }
    
                if(media==0x6 | media==0x7 | media==0x8 | media==0x9 | media==0xa | media==0xb)
    
                {
    
                  //printf("\n %d \n",rotateDVD(sectorsPerSecond));
    
                  spd.real=sectorsPerSecond;
    
                  spd.visible=rotateDVD(sectorsPerSecond);
    
          }
    
          sp.insert(sp.begin(),spd);
    
              }
    
              SafeArrayUnaccessData(ss);
    
              info.speeds=sp;
    
              //printf("%d",info.speeds[0].real);
    
            }
    
            }
    
            if(blank==VARIANT_FALSE)
    
            {
    
              /* */
    
        }
    
          }
    
          info.media=mt;
    
          info.fresz=freesize;
    
          info.totalsz=totalsize;
    
        }
    
        FD->Release();
    
        discRecorder->ReleaseExclusiveAccess();
    
        discRecorder->Release();
    
      }
    
    

    Юзаю вот так

    GetDiskInfo(RI[i].DeviceAccesId,DI);
    
        printf("%s disk size:%d\n",DI.media.c_str(),DI.totalsz);
    
        if(DI.speeds.size()>0)
    
        {
    
          printf("writing speeds: ");
    
          for(int j=0;j<DI.speeds.size();j++)
    
          {
    
            printf("%d X,%d",DI.speeds[j].visible,DI.speeds[j].real);
    
          }
    
          printf("\n");
    
        }
    
    
    Кол-во элементов вектора возвращяется правильное,но сами они(элементы) просто пустые :( Иcпользую Visual Studio 2008 Express SP1
    • Перемещено Tagore Bandlamudi 2 октября 2010 г. 21:09 MSDN Forums consolidation (От:Разработка Windows-приложений)
    14 сентября 2010 г. 18:09

Все ответы