C# Sample Program

The following C# example is all that is required to do the following:

___________________________________________________________

using DynaRithmic;
//....

[STAThread]
static void Main()
{
    int TwainOK = TwainAPI.DTWAIN_IsTwainAvailable()
    if ( TwainOK == 1 )
    {
        TwainAPI.DTWAIN_SysInitialize();
        int status = 0;
        int SelectedSource = TwainAPI.DTWAIN_SelectSource();
        if ( SelectedSource != 0 )
        {
            TwainAPI.DTWAIN_AcquireFile(SelectedSource,
                                        "Test.bmp",
                                         TwainAPI.DTWAIN_BMP,
                      TwainAPI.DTWAIN_USENATIVE | TwainAPI.DTWAIN_USELONGNAME,
                                         TwainAPI.DTWAIN_PT_DEFAULT,
                                         1,1,ref status);

            TwainAPI.DTWAIN_SysDestroy();
        }
    }
}

For C#, the DynaRithmic.TwainAPI is a class that wraps the DTWAIN functions. Note that it is as simple as calling five DTWAIN functions to get the job done.

Note that it is as simple as calling five DTWAIN functions to get the job done.  The C# project just adds the DTWAIN32.CS interface file to define the DTWAIN functions so that C# will recognize the functions such as DTWAIN_SysInitialize.

The documentation that comes with the DynaRithmic TWAIN Library discusses functions such as DTWAIN_AcquireFile in depth. It wasn't discussed here, but the goal of this small example is to show how simple it is to acquire images from a TWAIN device and save them to a file.  To acquire to the other file types other than BMP, the parameter that specifies DTWAIN_BMP can be any of the other file types such as DTWAIN_GIF, DTWAIN_JPEG, etc.. Therefore just 5 calls can save a file to any of many file types by just changing the third parameter to DTWAIN_AcquireFile.