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. How assign Variant type of data to safe array?

How assign Variant type of data to safe array?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorialquestion
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
    shir_k
    wrote on last edited by
    #1

    Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks

    I M 2 Replies Last reply
    0
    • S shir_k

      Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      I'm no COM expert, but isn't there a way to get the Variant to collapse to a BSTR? Then store that in your array. Just split the problem in two, and you have solvable bits. Iain.

      1 Reply Last reply
      0
      • S shir_k

        Hi, Am getting data from the serialport, when i call MComm->Getinput function to get the data from serial port, the data is stored in Variant type of data(result).I want to store this data in a safearray how to do that. VARIANT CMSComm::GetInput() { VARIANT result; InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY * psa; SAFEARRAYBOUND rgsabound[1]; VARIANT *pData; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 10; psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); var.vt=VT_ARRAY|VT_BSTR; SafeArrayAccessData(psa, (void HUGEP**)&pData); pData= result; // error:am not able to assign like this var.parray=psa; return var; } Thnaks

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        Your immediate problem would seem to be the need to use *pData = result; not that just changing that is going to make your code work. More generally if you're getting unparsed binary data in a VARIANT from a COM object isn't it already in a SafeArray? Check the type of the VARIANT and the contents of its array members. I suspect you'll find the VARIANT already is a SafeArray just disguised for COM/OLE Automation correctness. If not then I would do everything possible to keep the data away from SafeArrays which are code bloaty and awkward unless you're forced to interact with classic VB in which case they're also essential. Good luck.

        Nothing is exactly what it seems but everything with seems can be unpicked.

        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