Other Programming Languages

Top  Previous  Next

When using other Windows languages with DTWAIN, the guidelines to using DTWAIN successfully are as follows:

 

1) Be familiar with how your language calls third-party Dynamic Link Library functions.

Since DTWAIN is a Dynamic Link Library (DLL), you must have knowledge of how your language sets up calls to functions that are included in a DLL.  Most, if not all Microsoft Window's languages have capabilities to call DLL functions.  Usually the programmer's manual of the language would include examples of calling the various Windows API functions.  Use this as a guide to set up your interface to DTWAIN.  All of DTWAIN's functions follow the Windows API model, i.e. there are no proprietary variable types (like a Visual Basic String or some other data type) and the calls are all stdcall convention (this is not important unless you are using a language that does not follow this convention -- most languages do).  All of DTWAIN's functions require either a LONG integer type, a pointer to an array of characters or null terminated characters (LPTSTR or LPCTSTR), or the address of a variable (for example, an LPLONG).

 

Most if not all problems start with developers not being familiar with calling DLL's from the language that they're using.  This is something that DTWAIN support cannot solve easily, since there are so many different Windows languages, and each has a way of calling or setting up a call to a function in a DLL.   Again, this subject should be covered in the user manual of the programming language.  Hopefully in your manual, it shows how to interface to a function that accepts an LPCTSTR or LPTSTR or how to pass an address of one of your languages variables.  If this is not explained in your programmer's manual, a lookup on the Internet for your language using a search engine (i.e. http://www.google.com, http://www.yahoo.com, etc.), or other advanced books on the language that you're using will give you more information.

 

2) Prototype the DTWAIN functions correctly for your language

This is another stumbling block that has been discovered for programmers using other languages that want to interface to DTWAIN.  Prototyping is simply making sure that the parameters that you are calling the DTWAIN function with are exactly the type that DTWAIN expects, and making sure that the return type for the DTWAIN function matches the correct data type for your programming language.  For example, DTWAIN_GetSourceProductName takes 3 parameters, a DTWAIN_SOURCE, a pointer to an array of characters, and a LONG denoting the length.  The return value is a LONG.  This is is equivalent to providing the following:

 

Parameters:

32-bit integer (DTWAIN_SOURCE)

Pointer to array of char (LPTSTR)

32-bit integer (Length)

 

On return:

32-bit integer.

 
3) Determine if your language fully supports 64-bit IEEE floating point values

If your language does not support or properly support 64-bit IEEE floating point variables and values, you will need to use the alternate DTWAIN functions that use string parameters.  Please see the section on Floating Point Issues for more information.

 

4) Proper usage of the DTWAIN constants

Another source of problems is improper use of the DTWAIN constants.  Note that the constants used by the various DTWAIN functions are numerical constants, i.e. they are LONG integer values.  They are not strings or character arrays.  For example, DTWAIN_CAPSET is a numerical LONG integer -- it is not the string "DTWAIN_CAPSET".

 

To find out the actual value of DTWAIN constants, the DTWAINC.H file has a list of all the constants and their respective values.  Even though this file is a 'C' language header file, it is very easy to find the value by opening the file in a text editor and finding the correct value.

 

5) Start with the simple DTWAIN code

Always attempt to make sure the following calls are successful:

 

DTWAIN_SysInitialize (check for non-zero here)
DTWAIN_SelectSource (check if TWAIN dialog is displayed -- select a Source )
DTWAIN_AcquireFile  (acquire only a single page)
DTWAIN_SysDestroy

 

These are the four functions that you should always attempt first.  Once these work correctly, you are on your way to getting DTWAIN working successfully for you.