Locating and Loading the TWAIN DSM File

Top  Previous  Next

When the DTWAIN_StartTwainSession function is called with a NULL second argument, DTWAIN searches the local file system for the appropriate TWAIN DSM file (either TWAIN_32.DLL or TWAINDSM.DLL).

 

By default, DTWAIN will search the following directories in the order below to find the DSM file:

 

1)The directory that is designated as the WINDOWS directory by the system.  The WINDOWS directory is the directory returned by calling the Windows API function GetWindowsDirectory.
2)The directory that is designated as the SYSTEM directory by the system.  The SYSTEM directory is the directory returned by calling the Windows API function GetSystemDirectory.
3)The Windows operating system search logic when attempting to find Dynamic Link Library (DLL) files.

 

If the TWAIN_32.DLL or TWAINDSM.DLL file is not found in either 1), 2), or 3) above, then DTWAIN will return an error whenever a function is called that requires the TWAIN DSM to be loaded in memory.  This includes opening a TWAIN Data Source and various other functions.

 

The first directory where TWAIN_32.DLL or TWAINDSM.DLL is found in will be the version that will be loaded by DTWAIN_StartTwainSession.  For example, if TWAIN_32.DLL is found in the WINDOWS directory first, then that is the version that will be used (thus not necessary to search in the SYSTEM or have the OS search for the DSM file).

 

If the DSM file can be found, but the DSM file is not a valid TWAIN DSM file, an error is also returned.  This ensures that any other files that are named TWAIN_32.DLL or TWAINDSM.DLL that are not true DSM files will not be used.

 

To get the full path name of the DSM that DTWAIN will eventually use (or is currently using), you can call the DTWAIN_GetDSMFullName function.

 

Additional Search Order Options

 
In addition to the search order described above, DTWAIN can allow the application to set the search order for finding the TWAIN DSM, as well as limit the number of directories to search.  For example, your application may want to only search the WINDOWS directory for the DSM file, and if not found, return an error.  See the DTWAIN_SetDSMSearchOrder function for setting this option.