当前位置: 首页>>代码示例>>C++>>正文


C++ COleSafeArray::GetUBound方法代码示例

本文整理汇总了C++中COleSafeArray::GetUBound方法的典型用法代码示例。如果您正苦于以下问题:C++ COleSafeArray::GetUBound方法的具体用法?C++ COleSafeArray::GetUBound怎么用?C++ COleSafeArray::GetUBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在COleSafeArray的用法示例。


在下文中一共展示了COleSafeArray::GetUBound方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Sort

void CMainFrame::Sort(VARIANT* vArray)
{
   COleSafeArray sa;
   BSTR *pbstr;
   TCHAR buf[1024];
   LONG cElements, lLBound, lUBound;
  
   //needed for OLE2T macro below, include afxpriv.h
   USES_CONVERSION;

   // Type check VARIANT parameter. It should contain a BSTR array
   // passed by reference. The array must be passed by reference it is
   // an in-out-parameter.
   if (V_VT(vArray) != (VT_ARRAY | VT_BSTR))
   {
      AfxThrowOleDispatchException(1001, 
         _T("Type Mismatch in Parameter. Pass a string array by reference"));
   }

   // clears data in sa and copies the variant data into sa
   sa.Attach(*vArray);

   // Check that array is 1 dimensional
   if (sa.GetDim() != 1)
   {
      AfxThrowOleDispatchException(1002, 
         _T("Type Mismatch in Parameter. Pass a one-dimensional array"));
   }

   try 
   {
      // Get array bounds.
      sa.GetLBound(1, &lLBound);
      sa.GetUBound(1, &lUBound);

      // Get a pointer to the elements of the array
      // and increments the lock count on the array
      sa.AccessData((LPVOID*)&pbstr);

      //get no. of elements in array
      cElements = lUBound - lLBound + 1;
      for (int i = 0; i < cElements; i++)
      {
         //output the elements of the array
         _stprintf_s(buf, 1024, _T("[%s]\n"), OLE2T(pbstr[i]));
         OutputDebugString(buf);
      }
      
      //decrement lock count
      sa.UnaccessData();
   }
   catch (COleException *pEx)
   {
      AfxThrowOleDispatchException(1003, 
         _T("Unexpected Failure in FastSort method"));
      pEx->Delete();
   }
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:58,代码来源:colesafearray--accessdata_1.cpp

示例2: read_data

void read_data(void)
{
    COleSafeArray array;

    int col = 0;
    LONG liSamplesAvailable, liChannelHND;

    liChannelHND = g_TTLLive->GetFirstChannelHND();
    while( liChannelHND > -1 ) {

        if( col == 0 )printf("\n\rData ");

        liSamplesAvailable = g_TTLLive->SamplesAvailable[liChannelHND];

        if( liSamplesAvailable ) {
            array = g_TTLLive->ReadChannelDataVT(liChannelHND, liSamplesAvailable );
        }

        // If any samples available, we simply print out value of the first one
        array.GetUBound(1,&liSamplesAvailable );
        if( liSamplesAvailable ) {
            LONG liIndice = 0;
            FLOAT fData;

            array.GetElement(&liIndice,&fData);

            printf("%c:%6.3f, ",(char)('A'+liChannelHND), fData);

        } else {
            printf("%c:NO DATA, ",(char)('A'+liChannelHND));
        }

        col++;
        if( col >= 5)col = 0;

        liChannelHND = g_TTLLive->GetNextChannelHND();
    }
    printf("\n\r");
}
开发者ID:Faham,项目名称:emophiz,代码行数:39,代码来源:42_Reading_VARIANT_Data_MFC.cpp

示例3: __declspec

void __declspec(dllexport) __stdcall Access2DArray(SequenceContext *seqContext,  short *errorOccurred, long *errorCode, char errorMsg[1024])
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double *        numArray = NULL;
    long            firstDimSize, secondDimSize, numberDimensions;
    BOUNDSELEMENT   *pBounds = NULL;
    PropertyObjectPtr   seqContextPOPtr;

    TRY
        // Set sequence context as a property object
    seqContextPOPtr = seqContext->AsPropertyObject();

    if (seqContextPOPtr->Exists("Locals.Array2D", 0)) 
        {
            // Create a Safe Array from the VARIANT which contains a
            // copy of the Locals.NumericArray. 
        COleSafeArray safeArray;
        safeArray.Attach(seqContextPOPtr->GetValVariant("Locals.Array2D",0));

            // Lock array for data access and get a pointer to the data.
            // (assuming it's an array of doubles)
        safeArray.AccessData((void**)&numArray);

            // Get number of dimensions of safearray
        numberDimensions = safeArray.GetDim();

            // Allocate data to hold dimension sizes
        pBounds = (BOUNDSELEMENT*)malloc(numberDimensions * sizeof(BOUNDSELEMENT));
        if (pBounds == NULL)
            AfxThrowMemoryException();
        
            // Get dimension sizes
        for (long i = 0; i<numberDimensions; i++)
            {
            safeArray.GetLBound(i+1, &pBounds[i].lowerBound);
            safeArray.GetUBound(i+1, &pBounds[i].upperBound);
            }

        if (numberDimensions == 2)  // 2-D array only
            {
            firstDimSize = pBounds[0].upperBound - pBounds[0].lowerBound + 1;
            secondDimSize = pBounds[1].upperBound - pBounds[1].lowerBound + 1;              

                // Display data using LabWindows/CVI library function   
                // Remove comments to display waveforms
            
				if (CVI_YGraphPopup(seqContext->EngineAsDispatch, "Data in Local Array 1", &numArray[0*secondDimSize], secondDimSize) < 0)
                    AfxThrowMemoryException();
                if (CVI_YGraphPopup(seqContext->EngineAsDispatch, "Data in Local Array 2", &numArray[1*secondDimSize], secondDimSize) < 0)
                    AfxThrowMemoryException();
            
            }

        free(pBounds);

            // unlock array 
        safeArray.UnaccessData();
        }

    CATCH(COleDispatchException, e) 
        *errorOccurred = TRUE;
        _mbsnbcpy_s((unsigned char *)errorMsg, 1024, (unsigned char *)LPCTSTR(e->m_strDescription), 1024 - 1);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = e->m_scError;

    AND_CATCH(CMemoryException, e)
        if (pBounds)
            free(pBounds);
        *errorOccurred = TRUE;
        e->GetErrorMessage(errorMsg, 1024);
        *(errorMsg + (1024 - 1)) = '\0';
        *errorCode = TS_Err_OutOfMemory;

    END_CATCH 
}
开发者ID:afeique,项目名称:ni-training-july-2016,代码行数:76,代码来源:AccessingArrays.cpp


注:本文中的COleSafeArray::GetUBound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。