CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2013
    Posts
    1

    COM Marshalling Problem

    I'm trying to send a byte array to an out-of-process COM object. On the receiving side, the byte array has invalid data.
    Here is my IDL definition:
    Code:
    HRESULT setData([in] BSTR name, [in, size_is(dataLen)] BYTE* data, [in] LONG dataLen);
    My calling implementation is:
    Code:
      BYTE* data = (BYTE *) CoTaskMemAlloc(tDataLen);
      CopyMemory(data, tData, tDataLen);  
      bool rc = SUCCEEDED(object->setData(_bstr_t(name), data, tdataLen));  
      CoTaskMemFree(data);
    The fields name and dataLen are passed through ok and the first byte of the array is passed through. Does anybody know what I need to change to get the whole array passed?

    Regards,
    Bill

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM Marshalling Problem

    There's nothing suspicious so far in your code, and the problem may be somewhere else. Try to isolate your problem and replicate it in a short and simple compilable project, and post it here to let us see where the problem may be.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: COM Marshalling Problem

    I'm not entirely sure you can send a raw data array out to another process just like that.
    it might work with an in-process COM server, but out of process will need some kind of marshalling telling the one process how many bytes of data to transfer between the process spaces of the 2 executables. just because your function has a DataLen, doesn't mean the whole COM marshalling system knows about this too.

    Sending arrays through COM is usually done with a SAFEARRAY.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM Marshalling Problem

    In fact, it's okay to send raw bytes, and size_is(dataLen) makes the trick be possible. Proxy/Stub library is built in accordance with the IDL, and takes care of marshaling. See the sample: AtlBytes.zip

    As I said, the problem's somewhere else.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured