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. Passing/receiving byte-arrays ?

Passing/receiving byte-arrays ?

Scheduled Pinned Locked Moved COM
questionc++comsysadmin
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
    StefanM
    wrote on last edited by
    #1

    Can someone please help me out!!! I just don't know how to pass/receive binary data between a VB6 client application and an ATL COM Server (EXE). How can I transform this into COM? HRESULT MyFunc( unsigned short* pbIn, long cbIn, unsigned short** ppbOut ); Where pbIn is of cbIn-size. The output shall be a size-dynamic buffer holding the result. Can I use VB6 to call this method using Byte arrays? Need help

    P J R 3 Replies Last reply
    0
    • S StefanM

      Can someone please help me out!!! I just don't know how to pass/receive binary data between a VB6 client application and an ATL COM Server (EXE). How can I transform this into COM? HRESULT MyFunc( unsigned short* pbIn, long cbIn, unsigned short** ppbOut ); Where pbIn is of cbIn-size. The output shall be a size-dynamic buffer holding the result. Can I use VB6 to call this method using Byte arrays? Need help

      P Offline
      P Offline
      pba_
      wrote on last edited by
      #2

      COM must know at runtime the size of the buffer you want to marshall. So in your case you should declare the method in your IDL file like this : interface XXX { HRESULT MyFunc( [in]long cbIn,[in,size_is(cbIn)] unsigned short *pbIn,[out]long* pbOut,[out,size_is( ,*pbOut)]unsigned short** ppbOut); }; Or if you want to use the automation marshaller you can pass the array as SAFEARRAY, which is a VARIANT compatible type.

      1 Reply Last reply
      0
      • S StefanM

        Can someone please help me out!!! I just don't know how to pass/receive binary data between a VB6 client application and an ATL COM Server (EXE). How can I transform this into COM? HRESULT MyFunc( unsigned short* pbIn, long cbIn, unsigned short** ppbOut ); Where pbIn is of cbIn-size. The output shall be a size-dynamic buffer holding the result. Can I use VB6 to call this method using Byte arrays? Need help

        J Offline
        J Offline
        Joao Vaz
        wrote on last edited by
        #3

        Hi Stefan, one way that to pass binary data is to use BSTRs, using the api SysAllocStringByteLen , this creates a string with binary data . I actually used that doing a atl com object that passed binary data to vb6. I don't remember well, but since VB6 work with unicode internally , i think that you must allocate 2*nBytes that you want to pass to VB, but I'm not sure if you really need to double the nª of bytes, so you should try the first one. It's not necessary with BSTR to pass the size, since their size is prefixed at the head of the data, and vb makes use of this. Hope this helps, Joao Vaz

        1 Reply Last reply
        0
        • S StefanM

          Can someone please help me out!!! I just don't know how to pass/receive binary data between a VB6 client application and an ATL COM Server (EXE). How can I transform this into COM? HRESULT MyFunc( unsigned short* pbIn, long cbIn, unsigned short** ppbOut ); Where pbIn is of cbIn-size. The output shall be a size-dynamic buffer holding the result. Can I use VB6 to call this method using Byte arrays? Need help

          R Offline
          R Offline
          Rashid Thadha
          wrote on last edited by
          #4

          See sample app of COM Variant and Safearrays at http://www.sellsbrothers.com/tools/CComSafeArray.zip It also uses VB Clients and C++ COM Object Best SafeArray Sample that I have seen (from chris sells site) :cool:

          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