Visual C++ 6.0 Syntax

 

In Version 6.0 of Visual C++, the MicroSoft Foundation Class (MFC) library provides an ActiveX interface. 
This topic describes how to use the interface with the LEADTOOLS ActiveX.
To add a LEAD Main ActiveX Control to your application, refer to the example in Loading and Displaying an Image . 
Alternatively, to create an instance of the LEAD control at run time, use the Create function, which has the following prototype:
BOOL Create( 
 LPCTSTR lpszWindowName, DWORD dwStyle,
 const RECT&rect, CWnd* pParentWnd, UINT nID,
 CFile* pPersist = NULL, BOOL bStorage = FALSE,
 BSTR bstrLicKey = NULL);
 
Provide parameters as follows:
lpszWindowName
 Use "", because the control window does not need a name.
 
dwStyle
 Use 0 for the default style.
 
&rect
 Use the CRect function. For example: CRect(0,0,50,50).
 
pParentWnd
 Use this to refer to the current window.
 
nID
 Use 0 for the default ID.
 
pPersist
 Use NULL.
 
bStorage
 Use FALSE.
 
bstrLicKey
 Use the LEADTOOLS license string, which is always the first line in the ltocx.lic file. 
 For example: "LEADTOOLS OCX Copyright (c) 1991-2009 LEAD Technologies, Inc." If you do not specify this string correctly, 
 the ActiveX will not work when you distribute your application.
 
For example:
CLEAD *m_Lead1=NULL;
static const WCHAR BASED_CODE _szLicString[] =
	L"LEADTOOLS OCX Copyright (c) 1991-2009 LEAD Technologies, Inc.";
m_Lead1 = new CLEAD;
// pass the license string to the CLEAD:: Create function.
// The CLEAD::Create expects a BSTR parameter and SysAllocString converts the
// WCHAR[] to a BSTR
BSTR lpLic = SysAllocString(_szLicString);
m_Lead1-> CreateControl ("", 0,CRect(0,0,2200,2200),this,0,NULL,FALSE,lpLic);
m_Lead1->ShowWindow(SW_HIDE);
SysFreeString(lpLic);
When getting or setting a property value, you must use a function that is created by adding a prefix to the property name.
To set a property value, the syntax is as follows: 
m_controlname.Setpropertyname(value);
For example:
m_Lead1->SetRubberBandLeft(value);
To get a property value, the syntax is as follows: 
value = m_controlname.Getpropertyname();
For example:
HeightFactor = m_Lead1.GetBitmapHeight();
To set a property array value, the syntax is as follows: 
m_controlname.Setpropertyname(index, value);
For example:
m_Lead1.SetRemapTable(MyIndex, (255 * Offset) / CurrentRange);
To get a property array value, the syntax is as follows: 
value = m_controlname.Getpropertyname(index);
For example:
m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(3)); // Copy the K plane
In Version 5.0 of Visual C++, the MicroSoft compiler also has a #import directive, which can be used to import 
type library information from an ActiveX control or COM Object.
To add any of the LEAD ActiveX Objects to your application you can use the following:
// get information for LEAD Raster Variant Object
#import  no_namespace, named_guids
// get information for LEAD Raster Twain Object
#import  no_namespace, named_guids
Then, you can create instances of the objects. The following shows how to create an instance of ILEADRasterTwain_U.
ILEADRasterTwain_U * pRasterTwain;
HRESULT hr = ::CoCreateInstance(CLSID_LEADRasterTwain_U, NULL, CLSCTX_ALL, IID_ILEADRasterTwain_U, (void **)&pRasterTwain);
if (FAILED(hr) || !pRasterTwain)
{
	::MessageBox (NULL, _TEXT("Failed to create a Raster Twain Object"), _TEXT("Error"), MB_OK);
	return;
}
Note that there are 3 different ways that you can access a COM Object's properties when you use the #import statement.
To set a property value, the syntax is as follows: 
1) pObject->put_propertyname(value);
2) pObject->Putpropertyname(value);
3) pObject->propertyname = value;
For example:
      
pRasterTwain->put_EnableMethodErrors(FALSE); //1
pRasterTwain->PutEnableMethodErrors(FALSE); //2
pRasterTwain->EnableMethodErrors = FALSE; //3
To get a property value, the syntax is as follows: 
1) pObject->Get_propertyname(&value);
2) value = pObject->Getpropertyname();
3) value = pObject->propertyname;
For example:
VARIANT_BOOL bVal;
pRasterTwain ->get_EnableMethodErrors(&bVal); //1
bVal = pRasterTwain ->GetEnableMethodErrors();//2
bVal = pRasterTwain ->EnableMethodErrors;     //3