| |
   
Support Home | Search | FAQ | Library | Order | Forum  
Home : Barcode Components : Programming
Q10027 - HOWTO: Barcode ActiveX Control:Exporting Image to an IStr...

Barcode ActiveX: 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:

  1. Uses CreateStreamOnHGlobal() to create a standard, COM, IStream object
  2. Calls QueryInterface to retrieve the IUnknown pointer;
  3. Packages the IUnknown pointer into a VARIANT;
  4. 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 object
CComPtr<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.

Related Articles
No Related Articles Available.

Article Attachments
BarImageExport.zip

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 9/8/2004.
Last Modified on 9/14/2004.
Last Modified by glitch.
Suggested by Unknown.
Article has been viewed 2230 times.
Rated 10 out of 10 based on 1 vote.
Print Article
Email Article