Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
1 ratings:
 5 out of 5     Rate this Document

How Do I Convert a CWIMAQ Object to a Variant in C++?

Primary Software: LabWindows/CVI Add-ons>>Vision Development Module
Primary Software Version: 5.0
Primary Software Fixed Version: N/A
Secondary Software:

Problem: Using Microsoft Visual C++ with IMAQ Vision for ComponentWorks, I get errors when attempting to use the CWIMAQVision.Add method on two images. It works fine for adding a constant to an image, using the following syntax:
CWIMAQVision.Add (SourceImage, COleVariant(4.0), DestImage);
I get errors when trying to use a similar method to add two images. I have a similar problem when attempting to use a CWIMAQStructuringElement as an input to CWIMAQVision.Morphology. What can I do?

Solution: The second argument of CWIMAQVision.Add is a variant, since it can accept either a constant or an IMAQ image as an operand. You cannot use a function like COleVariant (OperandImage) because a CWIMAQImage is not defined in the Variant datatype. You must first convert the image to a VARIANT by casting it to a DISPATCH variant type. The following code fragment illustrates the procedure of adding two CWIMAQImages (SourceImage and OperandImage) and placing the result in DestImage:
	VARIANT varImage;
varImage.vt = VT_DISPATCH;
varImage.pdispVal = (LPDISPATCH)OperandImage;
m_CWIMAQVision1.Add(SourceImage, varImage, DestImage);
The first line declares a new variant called varImage. The second line specifies that the data in the variant will be of variant type DISPATCH, The third line sets the value of the pointer to the dispatch object as the typecast of a CWIMAQImage.

For more information on performing functions like casting in Visual C++, please check out the Microsoft Developer's Network at the Related Link below.

Related Links: Microsoft Developer's Network

Attachments:





Report Date: 05/25/2000
Last Updated: 02/21/2001
Document ID: 1XOELGL4

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit