Board index » cppbuilder » Returning binary data from COM ?

Returning binary data from COM ?

I may have missed something basic here .. but I want to return a few KB's of
binary data from a COM object - and use from script, web page, and from C++
if possible.

I'm unsure of how you'd go about using array-of-char, and if you do use
that, how would you use it from the script side? What I would like to do is
something like:

set picture = mycomp.export(sizeX,sizeY)
response.binarywrite picture
In other words, read a picture ( as the stream of bytes ) from the component
which is written in CBuilder and just pass it on with binarywrite. But all
attempts I do to return binary data breaks at the first NULL character -
since the BSTR, Variant or WideString conversions break at null :/

/Micke, sweden.

 

Re:Returning binary data from COM ?


I have exactly the same problem as you. But I discovered that you can use the "SAFEARRAY"-construct to build arrays.
I.E. instead of using BSTR (which doesn't match your requirements) you use "SAFEARRAY(unsigned char)". The VisualBasic equivalent of this type is "Byte()".
Borland C++ Builder translates this type to LPSAFEARRAY. But you should use the "TSafeArray" wrapper (see "safearry.h") to access this parameter from C++.
But this dosn't solve my Problem to access arrays in a comfortable way in C++ by using arrays of chars instead of TSafeArray.
The COM IDL supports the type "unsigned char [*]" but not so the Borland TBL editor. You would be very happy if you could tell me
when you get a solution to this problem.

Quote
"Micke" <Mi...@ekcimNO.SPAM.net> wrote:
>I may have missed something basic here .. but I want to return a few KB's of>binary data from a COM object - and use from script, web page, and from C++
>if possible.

>I'm unsure of how you'd go about using array-of-char, and if you do use
>that, how would you use it from the script side? What I would like to do is
>something like:

>set picture = mycomp.export(sizeX,sizeY)
>response.binarywrite picture

>In other words, read a picture ( as the stream of bytes ) from the component
>which is written in CBuilder and just pass it on with binarywrite. But all
>attempts I do to return binary data breaks at the first NULL character -
>since the BSTR, Variant or WideString conversions break at null :/

>/Micke, sweden.

Other Threads