-
August 14th, 2013, 12:18 PM
#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
-
August 19th, 2013, 03:50 PM
#2
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
-
August 20th, 2013, 09:41 AM
#3
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.
-
August 20th, 2013, 10:12 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|