C# Development

Top  Previous  Next

For C# development, it is recommended you use the Unicode versions of the DTWAIN DLLs.  The DLLs are DTWAIN32U.DLL and DTWAIN64U.DLL.

 

If you have developed an application using DTWAIN prior to version 4.x and wish to continue developing your application using DTWAIN 4.x or higher, it is highly recommended that you change the DTWAIN DLL to DTWAIN32U.DLL or DTWAIN64U.DLL.  Doing this will ensure that Unicode strings in .NET are marshaled properly to the DTWAIN DLL functions.  In addition, you must use the DTWAIN32U.CS or DTWAIN64U.CS interface file instead of DTWAIN32.CS or DTWAIN64.CS.

 

Please note: If you are building a 64-bit application, you will be using DTWAIN64U.DLL, not DTWAIN32U.DLL.

 

The DTWAIN32U.DLL or DTWAIN64U.DLL must be installed either in your application's directory, or in a directory that is specified in your system's PATH environment variable.

 

Included in the DTWAIN installation is a C# interface file DTWAIN32U.CS, or if you're building a 64-bit application, DTWAIN64U.CS.  All you need to do is to add this file in your C# project:

 

csharp

 

 

The DTWAIN interface is in the Dynarithmic namespace, and the calls are defined in class TwainAPI.

 

The following small application shows how to use the C# interface:

 

namespace WindowsApplication

{

   using Dynarithmic;

 

   static void Main()

   {

               int status=0;

 TwainAPI.DTWAIN_SysInitialize( );

 int Source = TwainAPI.DTWAIN_SelectSource( );

 TwainAPI.DTWAIN_AcquireFile(Source, "test.bmp", TwainAPI.DTWAIN_BMP,

      TwainAPI.DTWAIN_USENAME + TwainAPI.DTWAIN_USENATIVE,

                     TwainAPI.DTWAIN_PT_DEFAULT, 1, 1, 1, ref  status);

 TwainAPI.DTWAIN_SysDestroy( );

   }

}

 

Note the using clause states that the namespace to use is Dynarithmic, and the class TwainAPI contains the DTWAIN functions and constants.