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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. get SafeArray data......

get SafeArray data......

Scheduled Pinned Locked Moved ATL / WTL / STL
helpdatabasecomdata-structuresquestion
4 Posts 2 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.
  • V Offline
    V Offline
    vijay victory
    wrote on last edited by
    #1

    Hi Experts, I m devlopeing a COM application which takes one string and gives list of similar words. for that purpose I have used VARIANT* to store and return the list. My code for the exported function is as : LngGenSugg( BSTR* pcIpIscii, VARIANT *pacSuggArray, int* piNSugg, LFONT lfIOLayout, int *iResult) { // TODO: Add your implementation code here USES_CONVERSION; char buffer[20]; HRESULT hr= S_OK; // Create SafeArray of VARIANT BSTRs SAFEARRAY *pSA; SAFEARRAYBOUND aDim[1]; aDim[0].lLbound= 0; aDim[0].cElements= WordLen +1; pSA= SafeArrayCreate(VT_BSTR,1,aDim); if (pSA != NULL) { _variant_t vOut; VariantInit(&vOut); vOut.vt= VT_BSTR; // set type long aLong[1]; for (LONG l= aDim[0].lLbound; l< (aDim[0].cElements + aDim[0].lLbound); l++) { aLong[0]= l; // set index value ltoa(l,buffer,10); vOut.bstrVal = A2W("Victory"); if((hr= SafeArrayPutElement(pSA, aLong, &vOut)) != S_OK) { SafeArrayDestroy(pSA); // does a deep destroy return hr; } MessageBox(NULL,(char*)pSA[l].pvData ,"pSA",0); } } V_VT(pacSuggArray)= VT_ARRAY | VT_BSTR; V_ARRAY(pacSuggArray)= pSA; // (pSA may be null) . . . . } I just try to give words as "Victory"; so Is it correct way to do thiss??? and Exception occured during execution at MessageBos() cal. can anyone help me?? and Another problem is.. I have tried the same function by using char** str Array that stores similar words list but.. I m failed to assing it to return VARIANT array pacSuggArray. so plz help me.. Thanx in advance... waiting for ur valuable reply... regards , Victory

    J 1 Reply Last reply
    0
    • V vijay victory

      Hi Experts, I m devlopeing a COM application which takes one string and gives list of similar words. for that purpose I have used VARIANT* to store and return the list. My code for the exported function is as : LngGenSugg( BSTR* pcIpIscii, VARIANT *pacSuggArray, int* piNSugg, LFONT lfIOLayout, int *iResult) { // TODO: Add your implementation code here USES_CONVERSION; char buffer[20]; HRESULT hr= S_OK; // Create SafeArray of VARIANT BSTRs SAFEARRAY *pSA; SAFEARRAYBOUND aDim[1]; aDim[0].lLbound= 0; aDim[0].cElements= WordLen +1; pSA= SafeArrayCreate(VT_BSTR,1,aDim); if (pSA != NULL) { _variant_t vOut; VariantInit(&vOut); vOut.vt= VT_BSTR; // set type long aLong[1]; for (LONG l= aDim[0].lLbound; l< (aDim[0].cElements + aDim[0].lLbound); l++) { aLong[0]= l; // set index value ltoa(l,buffer,10); vOut.bstrVal = A2W("Victory"); if((hr= SafeArrayPutElement(pSA, aLong, &vOut)) != S_OK) { SafeArrayDestroy(pSA); // does a deep destroy return hr; } MessageBox(NULL,(char*)pSA[l].pvData ,"pSA",0); } } V_VT(pacSuggArray)= VT_ARRAY | VT_BSTR; V_ARRAY(pacSuggArray)= pSA; // (pSA may be null) . . . . } I just try to give words as "Victory"; so Is it correct way to do thiss??? and Exception occured during execution at MessageBos() cal. can anyone help me?? and Another problem is.. I have tried the same function by using char** str Array that stores similar words list but.. I m failed to assing it to return VARIANT array pacSuggArray. so plz help me.. Thanx in advance... waiting for ur valuable reply... regards , Victory

      J Offline
      J Offline
      Jonathan Davies
      wrote on last edited by
      #2

      You seem to be creating an array of type VT_BSTR, which is fine, but then complicating things somewhat. I'd recommend using SafeArrayAccessData to get a pointer, say pData, to your array of BSTR pointers then in a loop using pData[n] = SysAllocString(L"Victory"); to set the pointers and then SafeArrayUnaccessData at the end.

      V 1 Reply Last reply
      0
      • J Jonathan Davies

        You seem to be creating an array of type VT_BSTR, which is fine, but then complicating things somewhat. I'd recommend using SafeArrayAccessData to get a pointer, say pData, to your array of BSTR pointers then in a loop using pData[n] = SysAllocString(L"Victory"); to set the pointers and then SafeArrayUnaccessData at the end.

        V Offline
        V Offline
        vijay victory
        wrote on last edited by
        #3

        Thanx ur reply... If I want to assign my char *str[50] array of word list to that safearray. then what should I do? Do I assign each word from str array as above or. Is there any another way.. that I can assign just address of str array to safearray?? plz reply.. I m waitng for ur valuable reply. regards, Victory

        J 1 Reply Last reply
        0
        • V vijay victory

          Thanx ur reply... If I want to assign my char *str[50] array of word list to that safearray. then what should I do? Do I assign each word from str array as above or. Is there any another way.. that I can assign just address of str array to safearray?? plz reply.. I m waitng for ur valuable reply. regards, Victory

          J Offline
          J Offline
          Jonathan Davies
          wrote on last edited by
          #4

          Using the method mentioned its only memory for the BSTRs (which are pointers) that been assigned so to get a complete string you'd need to assign memory somehow. Using SysAllocString takes care of that for you and also looks after the length of the string, something that could complicate matters. You can assign memory to the SAFEARRAYS data area, if the rest of the SAFEARRAY has been setup to expect the type of data you put there. Personally I'd get it working using the method mentioned before looking for other ways but I'm sure there are plenty of articles etc on other ways.

          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