0

Please guide me on how to create a C# wrapper to access the methods of the tesseract library which is in C++.

George
  • 71
  • 11
  • http://www.pixel-technology.com/freeware/tessnet2/ – Uwe Keim May 03 '12 at 05:22
  • I have tried the below mentioned link, https://groups.google.com/forum/#!msg/tesseract-ocr/3sLKXOTVwyU/28XKruPnFwMJ – George May 03 '12 at 05:44
  • 1
    @UweKeim Thank you for your update, My goal is to create a C# wrapper library similar to tessnet2 and i cannot use tessnet2. – George May 03 '12 at 06:14

1 Answers1

5

Here is a good article on CodeProject you can follow.

When choosing an approach to reusing unmanaged libraries, you normally have three options:

  1. IJW or It Just Works. This is one of the greatest features that .NET Framework has provided to developers. You just recompile the old code on the new .NET platform. No or little changes are necessary. Don't forget though; it works in the C++ language only.
  2. COM. The COM model works on both the unmanaged and managed environments. It's straightforward to perform a COM Invoke on .NET. But, if your unmanaged classes are not COM-ready, you probably won't rewrite all the old code to support COM.
  3. P/Invoke or Platform Invoke. This mechanism allows you to import a class as functions at the attribute level. Basically, you import class methods one by one as individual functions, as you do with Win32 APIs.

For your case I will suggest the PlaPlatform Invocation Services (PInvoke). It allows managed code to call unmanaged functions that are implemented in a DLL. For example have a look on this MSDN code

// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
    [DllImport("msvcrt.dll")]
    public static extern int puts(string c);
    [DllImport("msvcrt.dll")]
    internal static extern int _flushall();

    public static void Main() 
    {
        puts("Test");
        _flushall();
    }
}

There is also an older post related to this, you can check it here.

Community
  • 1
  • 1
ABH
  • 3,391
  • 23
  • 26