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. COM
  4. SafeArray

SafeArray

Scheduled Pinned Locked Moved COM
data-structurestutorial
4 Posts 4 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
    Sameer Maggon
    wrote on last edited by
    #1

    Hi, I want to return Binary data i've read from a file. I know it can be done by safe array.. can nebody give me some hint on how to do that Regards Sameer

    P S L 3 Replies Last reply
    0
    • S Sameer Maggon

      Hi, I want to return Binary data i've read from a file. I know it can be done by safe array.. can nebody give me some hint on how to do that Regards Sameer

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      Use the type VT_U1 to store the binary data.

      1 Reply Last reply
      0
      • S Sameer Maggon

        Hi, I want to return Binary data i've read from a file. I know it can be done by safe array.. can nebody give me some hint on how to do that Regards Sameer

        S Offline
        S Offline
        soptest
        wrote on last edited by
        #3

        soptest

        1 Reply Last reply
        0
        • S Sameer Maggon

          Hi, I want to return Binary data i've read from a file. I know it can be done by safe array.. can nebody give me some hint on how to do that Regards Sameer

          L Offline
          L Offline
          Len Holgate
          wrote on last edited by
          #4

          I do something similar (return binary data in a safe array) in my COM Mailslots article. The code in question is:

          STDMETHODIMP CMailslotData::Read(VARIANT *ppResults)
          {
          if (!ppResults)
          {
          return E_POINTER;
          }

          return CreateSafeArray(m_pData, m_length, ppResults);
          }

          where m_pData points to the bytes of data and m_length is the number of bytes we have.

          HRESULT CreateSafeArray(
          BYTE *pData,
          DWORD dataLength,
          VARIANT *ppResults)
          {
          SAFEARRAYBOUND sab;
          sab.cElements = dataLength;
          sab.lLbound = 0;

          SAFEARRAY *pSa = SafeArrayCreateEx(VT_UI1, 1, &sab, 0);

          PVOID pvData;

          HRESULT hr = SafeArrayAccessData(pSa, &pvData);

          if (SUCCEEDED(hr))
          {
          ::CopyMemory(pvData, pData, dataLength);

            hr = ::SafeArrayUnaccessData(pSa);
          

          }

          if (SUCCEEDED(hr))
          {
          ::VariantInit(ppResults);

            (\*ppResults).parray = pSa;
            (\*ppResults).vt = VT\_ARRAY | VT\_UI1;
          

          }

          return hr;
          }

          Hope this helps. Len Holgate www.jetbyte.com The right code, right now.

          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