I want to create external component for export written in C# .NET. I used sample export script from ABBYY FlexiCapture 11 HELP and follow all steps described in HELP, but I have some trouble during building DLL file.
Part of script from help:
using System;
using System.Runtime.InteropServices;
using System.IO;
using ABBYY.FlexiCapture;
namespace ExportLibrary1
{
// The interface of the export component which can be accessed from the script
// When creating a new component, generate a new GUID
[Guid("32B10C3B-EEA3-4194-B0A0-E358C310225A")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _cExport
{
[DispId(1)]
void ExportDocument(ref IExportDocument DocRef, ref FCTools Tools);
}
// The class that implements export component functionality
// When creating a new component, generate a new GUID
// and set your ProgId
[Guid("3BA19BD7-C6DC-4f63-BC08-0D95254DADC3")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ExportLibrary1.Export")]
[ComVisible(true)]
public class Export : _cExport
{
public Export()
{
}
// The function carries out document export: creates an export folder and
// saves in it page image files,
// the text file with document fields, and information about the document
public void ExportDocument( ref IExportDocument docRef, ref FCTools FCTools )
{
try
{
string exportFolder = createExportFolder( docRef.DefinitionName );
exportImages( docRef, FCTools, exportFolder );
// creating the text file
string fileName = exportFolder + "//" + "doc.txt";
StreamWriter sw = File.CreateText( fileName );
// exporting info about document
exportDocInfo( docRef, sw );
// exporting fields
sw.WriteLine( "Fields:" );
exportFields( docRef.Children, sw, "" );
sw.Close();
}
catch( Exception e )
{
docRef.Action.Succeeded = false;
docRef.Action.ErrorMessage = e.ToString();
}
}
}
}
When I try to build DLL I got error :
Error 2 'ref ABBYY.FlexiCapture.FCTools': static types cannot be used as parameters C:\Projects\VBProjects\ExportLibrary1\ExportLibrary1\Class1.cs 34 21 ExportLibrary1
I come from Java world and I don’t know that is possible to send static class as a parameter to the function in C# .NET.
I changed ref FCTools FCTools as Object Tools in _cExport interface > ExportDocument function and then I can build DLL file and run component too from FC, but now I have a problem with calling static functions of FCTools static class. If I call any function(example: FCTools.ShowMessage(“Test”)) I got [Processing error]: Object reference not set to an instance of an object.
How to solve this problem?
Part of script from help:
using System;
using System.Runtime.InteropServices;
using System.IO;
using ABBYY.FlexiCapture;
namespace ExportLibrary1
{
// The interface of the export component which can be accessed from the script
// When creating a new component, generate a new GUID
[Guid("32B10C3B-EEA3-4194-B0A0-E358C310225A")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _cExport
{
[DispId(1)]
void ExportDocument(ref IExportDocument DocRef, ref FCTools Tools);
}
// The class that implements export component functionality
// When creating a new component, generate a new GUID
// and set your ProgId
[Guid("3BA19BD7-C6DC-4f63-BC08-0D95254DADC3")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ExportLibrary1.Export")]
[ComVisible(true)]
public class Export : _cExport
{
public Export()
{
}
// The function carries out document export: creates an export folder and
// saves in it page image files,
// the text file with document fields, and information about the document
public void ExportDocument( ref IExportDocument docRef, ref FCTools FCTools )
{
try
{
string exportFolder = createExportFolder( docRef.DefinitionName );
exportImages( docRef, FCTools, exportFolder );
// creating the text file
string fileName = exportFolder + "//" + "doc.txt";
StreamWriter sw = File.CreateText( fileName );
// exporting info about document
exportDocInfo( docRef, sw );
// exporting fields
sw.WriteLine( "Fields:" );
exportFields( docRef.Children, sw, "" );
sw.Close();
}
catch( Exception e )
{
docRef.Action.Succeeded = false;
docRef.Action.ErrorMessage = e.ToString();
}
}
}
}
When I try to build DLL I got error :
Error 2 'ref ABBYY.FlexiCapture.FCTools': static types cannot be used as parameters C:\Projects\VBProjects\ExportLibrary1\ExportLibrary1\Class1.cs 34 21 ExportLibrary1
I come from Java world and I don’t know that is possible to send static class as a parameter to the function in C# .NET.
I changed ref FCTools FCTools as Object Tools in _cExport interface > ExportDocument function and then I can build DLL file and run component too from FC, but now I have a problem with calling static functions of FCTools static class. If I call any function(example: FCTools.ShowMessage(“Test”)) I got [Processing error]: Object reference not set to an instance of an object.
How to solve this problem?
Comments
6 comments
To avoid this error just change the name of parameter to something like FCToolsExt and use this name further.
But you can also remove this parameter from function and use the global reference to FCTools.
Error
So you can create this object in FC script and then pass it to your external lib as a parameter.
In order to create this object at FC side you should use the next code snippet:
IExportImageSavingOptions exportOptionsObject = FCTools.NewImageSavingOptions();
exportOptionsObject.Quality = 100;
exportOptionsObject.Format = "pdf";
exportOptionsObject.Resolution = 150;
Please let us know If you need FCTools for other proposes.
In order to see how to use FCTools object please download the project from the link https://www.dropbox.com/sh/moeem5rixoj310g/AABDKEafc03mQatJ_EcxUrboa?dl=0.
This project shows how to create your own export library and use FCTools.
Please sign in to leave a comment.