Discussion:
How to return binary-data from a ActiveX com-component?
(too old to reply)
Henri Schomäcker
2004-03-03 10:15:26 UTC
Permalink
Hi folks,

I'm trying to write a ActiveX com-component which has a function which
should return jpeg-image-data. Until now, I wanted to return it as a BSTR.

Inside the com component, I'm using a class of mine which returns
the jpeg-image-data in a char* string.

I tested the class in a little exe testproject, which directly returns the
image to the browser when used as a cgi-application.
This works fine using...
8<--------8<--------8<--------8<--------8<--------
  printf("Content-type: image/jpeg\r\n\r\n");
  setmode(fileno(stdout), _O_BINARY);
  fwrite(imgBuffer, imgSize, 1, stdout);
8<--------8<--------8<--------8<--------8<--------

In my com-component function getImage() I tried using...
8<--------8<--------8<--------8<--------8<--------
CComBSTR temp(imgBuffer);
*retstr = temp.Detach();
8<--------8<--------8<--------8<--------8<--------
...which returns a BSTR containing the image-data.
The Problem is, it's not in binary-mode now, gets formated and the image
doesn't display properly.

How can I replace the second snippet by some code to return imgBuffer in
binary-mode in a BSTR or other appropriate type which can then be returned
by the com-component? I found an article about a BSTR-wrapper-class, but
don't know if such a variable isn't formated again when I apppend it to
CComBSTR.

The goal is to easy access the image data with any scripting-language like
this (in vbscript, for axample):
8<--------8<--------8<--------8<--------8<--------
Response.ContentType = "image/jpeg"

Dim strImage
Dim objImage

Set objImage = Server.CreateObject("mytools.imgServer")
strImage = objImage.getImage()
Set objImage = Nothing
Response.BinaryWrite(strImage)
8<--------8<--------8<--------8<--------8<--------

Many thanks in advance,
    yours Henri
Alexei M. Kondratiev2050846129
2004-03-03 16:44:50 UTC
Permalink
Post by Henri Schomäcker
I'm trying to write a ActiveX com-component which has a function which
should return jpeg-image-data. Until now, I wanted to return it as a BSTR.
Inside the com component, I'm using a class of mine which returns
the jpeg-image-data in a char* string.
You should pass a variant of type VT_ARRAY | VT_UI1 to Response.BinaryWrite,
i.e. safearray of bytes.

Alexei Kondratiev
Henri Schomäcker
2004-03-04 15:39:38 UTC
Permalink
Post by Alexei M. Kondratiev2050846129
Post by Henri Schomäcker
I'm trying to write a ActiveX com-component which has a function which
should return jpeg-image-data. Until now, I wanted to return it as a BSTR.
Inside the com component, I'm using a class of mine which returns
the jpeg-image-data in a char* string.
You should pass a variant of type VT_ARRAY | VT_UI1 to
Response.BinaryWrite, i.e. safearray of bytes.
Alexei Kondratiev
Hi Alex,

I've read about the possibility to return a safearray, but wouldn't have the
user to loop throught the safearray in the using vbs-script?
I already thought about the solution to return only the first array-item,
but how is this done then? - Is it possible?
And what about _none_ vbs or c++ clients, such as e.g. a perl or php script?
Can they also access the as safearray returned data then?

Again, many thanks in advance,
yours Henri

Loading...