C# samples apply to Windows. C++ samples apply to all supported operating systems.
Linux and macOS property types
Linux and macOS property types
For C++, a property is a pair of methods (get and put for read-write properties) or a single get method (for read-only properties).The ABBYY FineReader Engine properties may be of the following types:
- VARIANT_BOOL (with two values VARIANT_TRUE or VARIANT_FALSE)
- int
- double
- BSTR, a pointer to Unicode string. Zero value specifies an empty string.
- __int64
- HANDLE*
- IUnknown-derived interface
- enum
Windows property types
Windows property types
C# and Visual Basic users are familiar with the notion of property.For a C++ user, a property is a pair of methods (get and put for read-write properties) or a single get method (for read-only properties).However, the “Native COM support” featured by Microsoft C++ makes the way the properties are handled more like the one used in C#.The ABBYY FineReader Engine properties may be of the following types:
| IDL | C++ | C# | Visual Basic .NET |
|---|---|---|---|
| VARIANT\_BOOL (VARIANT\_TRUE or VARIANT\_FALSE) | VARIANT\_BOOL (VARIANT\_TRUE or VARIANT\_FALSE) | bool (true or false) | Boolean (True or False) |
| int | int | int | Integer |
| double | double | double | Double |
| BSTR, a pointer to Unicode string. Zero value specifies an empty string. | BSTR | string | String |
| \_\_int64 | \_\_int64 | Int64 | Int64 |
| HANDLE\* | void\* | IntPtr | IntPtr |
| IUnknown-derived interface | IUnknown-derived interface | object | Object |
| enum | enum | enum | Enum |
Working with simple properties
Working with simple properties
We will use a Boolean property as an example of how simple properties are used. The property is described in the type library as follows:If the type library only defines the “get” method for a simple property, this property is called read-only. Its value cannot be changed by the user, it may only be accessed for “reading.”A C# user handles a simple property as follows:A C++ user, on the other hand, uses two methods to work with this property. These methods have get_ and put_ prefixes. The respective C++ code should look as follows:However, the Native COM support in Windows makes the procedure simpler, and the respective code should look as follows:
Working with string properties
Working with string properties
Working with string properties is very similar to working with simple properties, but has its own specifics. A C++ user working with string properties must free the strings that are passed to set-methods, and also those that are returned by get-methods.A C++ user works with this property like this:Windows:Linux:
- In Windows, this is done automatically in C#, Visual Basic, and in C++ with the Native COM support.
- In Linux, use the FREngineAllocString and FREngineFreeString functions to allocate and free the memory for the strings.
Working with object properties
Working with object properties
A C++ user will say that the parameters of “get” methods of object properties are pointers to an object’s interface pointer. As the interfaces of the objects are derived from IUnknown, they may be passed as IUnknown pointers to the properties or methods which use objects of several types as input or output parameters (you may, however, get the interface you need by calling the QueryInterface method).A “put” method for an object property, if any, supports clear put, described by the propput keyword in the type library. This means that the object is copied (instead of passing a pointer to an existing object’s interface).Suppose again the MyObject object supports MyObjectProperty property that refers to an object of MyChildObject type.A C++ user will write this code as follows:Note that in C++ you should call the Release method for an object got via a property. Native COM support in Windows calls AddRef and Release methods automatically using auto pointers.
