Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Safe Array

Safe Array

Scheduled Pinned Locked Moved C / C++ / MFC
databasecomdata-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    satsumatable
    wrote on last edited by
    #1

    Hi, I have the following prototype in ActiveX to send the Array from my client program. The variable VarArray contains array of values, Can you please provide me an example to get the values of each index by using SafeArray. void CSimpleAdditionAtxCtrl::Final(VARIANT* VarArray) { }

    A L 2 Replies Last reply
    0
    • S satsumatable

      Hi, I have the following prototype in ActiveX to send the Array from my client program. The variable VarArray contains array of values, Can you please provide me an example to get the values of each index by using SafeArray. void CSimpleAdditionAtxCtrl::Final(VARIANT* VarArray) { }

      A Offline
      A Offline
      alan top
      wrote on last edited by
      #2

      VARIANT varBuffer; ------------------ if(varBuffer.vt==(VT_ARRAY|VT_UI1)) { DWORD dwSize=varBuffer.parray->rgsabound[0].cElements; BYTE lpBuffer=new BYTE[dwSize]; memcpy( lpBuffer , varBuffer.parray->pvData,dwSize); delete []lpBuffer; } alantop

      1 Reply Last reply
      0
      • S satsumatable

        Hi, I have the following prototype in ActiveX to send the Array from my client program. The variable VarArray contains array of values, Can you please provide me an example to get the values of each index by using SafeArray. void CSimpleAdditionAtxCtrl::Final(VARIANT* VarArray) { }

        L Offline
        L Offline
        Laxman Auti
        wrote on last edited by
        #3

        sivaprakashshanmugam wrote:

        I have the following prototype in ActiveX to send the Array from my client program. The variable VarArray contains array of values, Can you please provide me an example to get the values of each index by using SafeArray.

        Here m_vecIcecreamFlavors and m_vecIcecreamPrices are vecters of BSTR and float resp. //Initialize the bounds for the array //Ours is a 2 dimensional array SAFEARRAYBOUND safeBound[2]; //Set up the bounds for the first index //That's the number of flavors that we have safeBound[0].cElements = m_vecIcecreamFlavors.size(); safeBound[0].lLbound = 0; //Set up the bounds for the second index safeBound[1].cElements = m_vecIcecreamPrices.size(); safeBound[1].lLbound = 0 ; ///Initialize the VARIANT VariantInit(VarArray); //The array type is VARIANT //Storage will accomodate a BSTR and a float pVariant->vt = VT_VARIANT | VT_ARRAY; pVariant->parray = SafeArrayCreate(VT_VARIANT,2,safeBound); //Initialize the vector iterators std::vector::iterator iterFlavor; std::vector::iterator iterPrices; //Used for indicating indexes in the Multidimensional array long lDimension[2]; int iFlavorIndex = 0; //Start iteration iterPrices = m_vecIcecreamPrices.begin(); iterFlavor = m_vecIcecreamFlavors.begin(); //Iterate thru the list of flavors and prices while(iterFlavor != m_vecIcecreamFlavors.end()) { //Put the Element at (0,0), (0,1) , (0,2) ,.............(0,n) lDimension[1] = iFlavorIndex; lDimension[0] = 0; CComVariant variantFlavor(SysAllocString((*iterFlavor).m_str)); SafeArrayPutElement(pVariant->parray,lDimension,&variantFlavor); //Put the Element at (1,0), (1,1) , (1,2) ,.............(1,n) lDimension[1] = iFlavorIndex; lDimension[0] = 1; CComVariant variantPrices(*iterPrices); SafeArrayPutElement(pVariant->parray,lDimension,&variantPrices); iFlavorIndex++; iterPrices++; iterFlavor++; } Suppose Variant result is parameter passed for fillup then we can retrive the elements from the array as follows. long lUDimension,lLDimension; SafeArrayGetUBound(result->parray,2,&lUDimension); SafeArrayGetLBound(result->parray,2,&lLDimension); VARIANT val[2]; long Dimension[2]; for(LONG i=lLDimension;i<=lUDimension;i++) { m_Data.InsertItem(i," "); Dimension[0]=0; Dimension

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups