예제 #1
0
ITunesEventInterface::ITunesIdSet
ITunesComEventSink::getIdsFromSafeArray( long index, 
                                         CComSafeArray<VARIANT>& array )
{
    VARIANT elem;
    LONG idx2d[2];

    idx2d[0] = index;
    idx2d[1] = 0;
    array.MultiDimGetAt( idx2d, elem );
    long sourceId = elem.lVal;

    idx2d[1] = 1;
    array.MultiDimGetAt( idx2d, elem );
    long playlistId = elem.lVal;

    idx2d[1] = 2;
    array.MultiDimGetAt( idx2d, elem );
    long trackId = elem.lVal;

    idx2d[1] = 3;
    array.MultiDimGetAt( idx2d, elem );
    long dbId = elem.lVal;

    ITunesEventInterface::ITunesIdSet ids = { sourceId, playlistId, trackId, dbId };
    return ids;
}
예제 #2
0
/**
 * Output = Map of topic id and field data  -  Map to be deleted by caller
 */
std::map<long,CComVariant>* RTDClient::readNewData(){    
    
    SAFEARRAY  *data_sa;
    long        topic_count = 0;
    HRESULT     hr          = comObjectScripRTD->RefreshData( &topic_count, &data_sa );      
                                                                 // Pass Address of SAFEARRAY pointer so that we get pointer to 2D safearray
    if( FAILED(hr) ){                                            // Output Data has to be deleted by client
        std::cout << "RefreshData COM failure." << " - hr - " << hr <<   std::endl;    
        return 0;
    }
    CComSafeArray<VARIANT>  data;                                // Passing data_sa as Constructor input will copy it, but we need to destroy it after use
    data.Attach( data_sa );                                      // So attach instead and let CComSafeArray handle it
    

    ULONG  row_count = data.GetCount(1);                         // No of Rows = 2nd Dimension Count
    if( row_count == 0) return 0 ;
        
    std::map<long,CComVariant> *output = new std::map<long,CComVariant>;    // Map: Topicid, Field Data
         
    long index[2];
    for( ULONG i=0 ; i<row_count; i++  ){
        
        index[0] = 0;                                            // 0,x - Topic ids.   1,x - Data
        index[1] = i;
        CComVariant topic_id_var;
        data.MultiDimGetAt( index, topic_id_var);         
        long topic_id = (long)MiscUtil::getLong( topic_id_var );
        
        index[0] = 1;
        index[1] = i;
        CComVariant topic_data_var;
        data.MultiDimGetAt( index, topic_data_var); 
                
        
        if( output->count(topic_id) != 0  && (*output)[topic_id] != topic_data_var  ){            
            std::cout << "Duplicate:";  MiscUtil::printVariant((*output)[topic_id]); std::cout << "-";  MiscUtil::printVariant(topic_data_var);
            std::cout << std::endl;
            //abort();                                           // If exists - we can have multiple topic values in same call => use vector
        }
        
        (*output)[topic_id] = topic_data_var;   
    } 

    return output;
}