HOWTO: Exporting Image to an IStream

Anything related to Barcode ActiveX programming

HOWTO: Exporting Image to an IStream

Postby glitch (legacy member) on Wed Sep 08, 2004 11:04 am

Exporting Image to an IStream
Summary
BarImageExport.zip is a Visual C++ 6.0 sample that shows you how to export image to an IStream object.

For performance or other reasons it may sometimes be desired to export the barcode image to the memory only as a stream of data.

The help document for Barcode ActiveX did not mention this feature because it is treated as an advanced topic.
The Morovia product, Morovia Barcode Server, uses the tactics outlined in this article. It retrieves the barcode to a memory stream, and then write the stream into the browser client. In this way no disk operation is involved.


More Information
Function definition
In the IDL, ExportImage is defined as

[id(DISPID_EXPORTIMAGE), helpstring("method ExportImage")] HRESULT
ExportImage([in, optional] VARIANT Destination, [in, defaultvalue(mbxFormatJPG)]
ImageFormatEnum ImageFormat);
The interface function takes two parameters. The first one is a VARIANT and the second one is an interger indicating the image format. The first parameter can contain two types - if it hodls a string, the parameter contains the path to the destination file. If it holds an IUnknown pointer, it is treated as an IStream object.


Exporting the image to an IStream object
This sample uses the following steps to export the barcode image:

Uses CreateStreamOnHGlobal() to create a standard, COM, IStream object
Calls QueryInterface to retrieve the IUnknown pointer;
Packages the IUnknown pointer into a VARIANT;
Calls the ExportImage to export the image into IStream object.
Code Highlights
Create Barcode Control at background
This step can be skipped if you create the Barcode ActiveX object in Visual Studio Form designer or other integrated programming environment.
(note: if you need distribute Morovia Barcode ActiveX control, you should use IclassFactory2 interface and pass your Company name as the license key to create the Barcode object).

//Create Morovia Barcode ActiveX objectCComPtr<IDispatch> spDisp;
HRESULT hr = spDisp.CoCreateInstance(L"Morovia.BarcodeActiveX");
if ( FAILED(hr) )
{
cerr << _T("Failed to load Morovia Barcode ActiveX object.") << endl;
cerr << _T("Please reinstall the ActiveX object using the installer provided")<< endl;cerr << _T("by Morovia Corporation.")<< endl;return -1;}
cout << _T("Morovia Barcode ActiveX loaded succesfully.") << endl;

Memory Stream
Create a standard memory IStream object and then retrieve its IUnknown interface.

CComPtr<IStream> spStream;CreateStreamOnHGlobal(NULL, TRUE, &spStream);CComPtr<IUnknown> spUnknown;spStream->QueryInterface(&spUnknown);

Make the Call
HRESULT hr = _com_dispatch_method(spDisp, 1004, DISPATCH_METHOD, VT_EMPTY,
(void*)(NULL), L"\x000D\x0003", spUnknown, 1);
In this sample we use the IDispatch interface to invoke the function. If you have the IBarcode interface pointer, you may use IBarcode pointer which is simpler:

CComVariant streamVar( spUnknown);
CComQIPtr<IBarcode> spBarcode(spDisp);
spBarcode->ExportImage(streamVar, 1);
The integer 1 indicates we ask for the JPEG format. For a series of image format supported by the control, refer to the Barcode ActiveX help.


Limitations
The current version 3.0 does not support retrieving Windows MetaFile format from IStream pointer. It returns E_INVALIDARG if you pass an IStream object and ask for a WMF output. All other formats, such as BMP, JPG, GIF, PNG and TIF are supported.



Edited by glitch on February 23 2005 at 4:26pm
glitch (legacy member)
 

Re: HOWTO: Exporting Image to an IStream

Postby glitch (legacy member) on Wed Sep 08, 2004 11:05 am

This article can be also found at Morovia Support Center:

http://www.morovia.com/support/article10027.html
glitch (legacy member)
 


Return to Barcode ActiveX Control

Who is online

Users browsing this forum: No registered users and 1 guest