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 Arrays in COM

Passing Arrays in COM

Scheduled Pinned Locked Moved COM
phpcomsysadmindata-structureshelp
4 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.
  • J Offline
    J Offline
    Johan O
    wrote on last edited by
    #1

    Need help with passing a BYTE array in COM. I think i have done it right but i only get the first byte passed. Here is the idl: interface ICOMtestObject : IUnknown { [id(1), helpstring("method GetData")] HRESULT GetData([out]ULONG *sz,[out,size_is(,*sz)]BYTE **data); }; Here is the implementation in the COM server: STDMETHODIMP CCOMtestObject::GetData(ULONG *sz, BYTE **data) { // TODO: Add your implementation code here *data = (BYTE*)CoTaskMemAlloc( 5 * sizeof( BYTE)); (*data)[0]='T'; (*data)[1]='e'; (*data)[2]='s'; (*data)[3]='t'; (*data)[4]='\0'; *sz=5; return S_OK; } Here is the implementation in the client: HRESULT hr = m_objPtr.CoCreateInstance(L"Comtest.COMtestObject.1"); ULONG sz;BYTE *data; hr = m_objPtr->GetData(&sz,&data); The data array includes only the first byte. Here are some sample code http://forums.devx.com/attachment.php?attachmentid=1036

    J L 2 Replies Last reply
    0
    • J Johan O

      Need help with passing a BYTE array in COM. I think i have done it right but i only get the first byte passed. Here is the idl: interface ICOMtestObject : IUnknown { [id(1), helpstring("method GetData")] HRESULT GetData([out]ULONG *sz,[out,size_is(,*sz)]BYTE **data); }; Here is the implementation in the COM server: STDMETHODIMP CCOMtestObject::GetData(ULONG *sz, BYTE **data) { // TODO: Add your implementation code here *data = (BYTE*)CoTaskMemAlloc( 5 * sizeof( BYTE)); (*data)[0]='T'; (*data)[1]='e'; (*data)[2]='s'; (*data)[3]='t'; (*data)[4]='\0'; *sz=5; return S_OK; } Here is the implementation in the client: HRESULT hr = m_objPtr.CoCreateInstance(L"Comtest.COMtestObject.1"); ULONG sz;BYTE *data; hr = m_objPtr->GetData(&sz,&data); The data array includes only the first byte. Here are some sample code http://forums.devx.com/attachment.php?attachmentid=1036

      J Offline
      J Offline
      Jurgen Jung
      wrote on last edited by
      #2

      As i can see, you want to pass a string, right ? Why don't use a "COM-String" ? [id(1), helpstring("method GetData")] HRESULT GetData([out, retval]BSTR* data); If you want to pass a "real" array, why don't you use a "COM-Array" ? [id(1), helpstring("method GetData")] HRESULT GetData([out, retval]SAFEARRAY* data);

      1 Reply Last reply
      0
      • J Johan O

        Need help with passing a BYTE array in COM. I think i have done it right but i only get the first byte passed. Here is the idl: interface ICOMtestObject : IUnknown { [id(1), helpstring("method GetData")] HRESULT GetData([out]ULONG *sz,[out,size_is(,*sz)]BYTE **data); }; Here is the implementation in the COM server: STDMETHODIMP CCOMtestObject::GetData(ULONG *sz, BYTE **data) { // TODO: Add your implementation code here *data = (BYTE*)CoTaskMemAlloc( 5 * sizeof( BYTE)); (*data)[0]='T'; (*data)[1]='e'; (*data)[2]='s'; (*data)[3]='t'; (*data)[4]='\0'; *sz=5; return S_OK; } Here is the implementation in the client: HRESULT hr = m_objPtr.CoCreateInstance(L"Comtest.COMtestObject.1"); ULONG sz;BYTE *data; hr = m_objPtr->GetData(&sz,&data); The data array includes only the first byte. Here are some sample code http://forums.devx.com/attachment.php?attachmentid=1036

        L Offline
        L Offline
        Lim Bio Liong
        wrote on last edited by
        #3

        Hello Johan, Since your interface is non-Automation-compatible, did you build the corresponding Proxy/Stub DLL ? I downloaded your source codes and did not notice any projects for a Proxy/Stub DLL. This is necessary especially since your COM server is an EXE. I'm surprised that your client code can even successfully call GetData(). Best Regards, Bio.

        J 1 Reply Last reply
        0
        • L Lim Bio Liong

          Hello Johan, Since your interface is non-Automation-compatible, did you build the corresponding Proxy/Stub DLL ? I downloaded your source codes and did not notice any projects for a Proxy/Stub DLL. This is necessary especially since your COM server is an EXE. I'm surprised that your client code can even successfully call GetData(). Best Regards, Bio.

          J Offline
          J Offline
          Johan O
          wrote on last edited by
          #4

          My mistake i forgot to compile the proxy-stub. Thanks

          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