| |
   
Morovia.com Home | Fonts | Components | Labeling | Library | Order | Forum
  Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Barcode ActiveX Control
 Community Forum : Barcode ActiveX Control
Subject Topic: HOWTO: Exporting Image to an IStream Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
glitch
Admin Group
Admin Group
Avatar

Joined: January 25 2003
Location: Canada
Posts: 280
Posted: September 08 2004 at 11:04am | IP Logged Quote glitch

 

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.



Edited by glitch on February 23 2005 at 4:26pm
Back to Top View glitch's Profile Search for other posts by glitch Visit glitch's Homepage
 
glitch
Admin Group
Admin Group
Avatar

Joined: January 25 2003
Location: Canada
Posts: 280
Posted: September 08 2004 at 11:05am | IP Logged Quote glitch

This article can be also found at Morovia Support Center:

http://www.morovia.com/support/article10027.html

Back to Top View glitch's Profile Search for other posts by glitch Visit glitch's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.3906 seconds.