Passing Arrays in COM
-
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
-
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
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);
-
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
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.
-
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.