Calling DTWAIN DLL Functions (C or C++)

Top  Previous  Next

For most programmers, using DTWAIN will require you to include the header file DTWAIN.H in any source file that calls DTWAIN functions, and specify an import library (the file with the .LIB extension) in your build settings so that the linker will find the DTWAIN functions that your application calls.  

 

The other way to successfully use DTWAIN is to use the Windows API functions LoadLibrary and GetProcAddress to load the DTWAIN DLL at runtime and to call the DTWAIN functions using function pointers.

 

The first method of using an import library is the preferred method, since there is very little setup on the programmer's part except to make sure that the import library is included in the build settings for the application.  The second method of calling DTWAIN functions (using LoadLibrary and GetProcAddress) is desirable for various reasons, one being that you don't need an import library, and second, any Windows C++ compiler can utilize DTWAIN, even if the compiler cannot generate import libraries.

 

The topic, Visual C++ and C Runtime Library Information, describes how to set up your application's build settings for usage of the import library method.  Note that this is Visual C++ specific.  If your compiler is not Visual C++ and you would like to utilize import libraries, you should investigate how to create import libraries from a DLL for your particular compiler.  Note that import libraries are incompatible between compiler brands and sometimes compiler versions.  For example, a Visual C++ 6.0 import library cannot be used in a C++ Builder 5.0 application.   DTWAIN includes import libraries for Visual C++ 5.0, 6.0/Net and Visual Studio 2005 - 2010, Borland C++ 5.0x, and C++ Builder.  It is just a matter of including the proper import library for your application run-time version and compiler.  See C and C++ import libraries for more information.

 

If you are using a C or C++ compiler that doesn't generate import libraries, or you would like to not use import libraries at all, you can utilize the method of using the  Windows API functions LoadLibrary and GetProcAddress to load the DTWAIN DLL library at runtime.  DTWAIN has support for this method, and information can be found in the topic Using DTWAIN without an import library. This is the preferred method for non-Visual C++ compilers such as Dev-C++, Digital Mars, CodeWarrior, etc.

 

If you have purchased a full DTWAIN license and would like to utilize the static DTWAIN libraries, please read the section on usage of the Static Libraries.

 

If you are attempting to build the enclosed DTWAIN C or C++ examples, and you wish to use an import library, make sure that the import library is in your library path settings or is included in your project's workspace, or specified on the command-line (if you are using a command-line driven compiler).  Errors when linking such as "could not find dtwain32.lib" or many errors where the linker cannot find the DTWAIN functions is almost always caused by not including the import library in your project, or the linker could not find the import library.