L_LTTWN_API L_INT L_TwainInitSession2(phSession, pAppData, uFlags)
|pHTWAINSESSION phSession;||pointer to a TWAIN session handle|
|pAPPLICATIONDATA pAppData;||pointer to the APPLICATIONDATA structure|
Initializes the TWAIN session.
|phSession||Pointer to a TWAIN session handle. This handle is needed to acquire pages from the TWAIN source, and work with template files, containers, capabilities, and properties.|
|pAppData||Pointer to an APPLICATIONDATA structure. This structure will have the handle of the parent window, in addition to other data about the application.|
|uFlags||Flags that indicate the function behavior. Possible values are:|
|LTWAIN_INIT_MULTI_THREADED||[0x0001] Initializes the TWAIN session with the multi-threaded option.|
|LTWAIN_INIT_USE_THUNKSERVER||[0x0002] Initializes the TWAIN session with the THUNK server option.|
|0||Behaves the same way L_TwainInitSession does.|
|SUCCESS||The function was successful.|
|! = SUCCESS||An error occurred. Refer to Return Codes.|
|ERROR_TWAIN_INVALID_DLL||(-561) Invalid DLL. Most likely, this is because an old version of TWAINDSM.DLL is in the system folder. Make sure you have at least version 22.214.171.124 of this DLL. Download the DLL from www.twain.org.|
|ERROR_TWAIN_NOT_INITIALIZED||(-562) Invalid DLL. TWAIN is not initialized. (Assuming that the LTWAIN_INIT_USE_THUNKSERVER flag is being used), The THUNK server (ltthunkserver.exe) failed to start. To resolve the error, make sure ltthunkserver.exe is registered correctly and that all dependencies listed in the Using the LEADTOOLS THUNK Utility with TWAIN topic reside in the same folder in which ltthunkserver.exe is located.|
L_TwainInitSession2 (or L_TwainInitSession) must be called before calling any other LEADTOOLS TWAIN toolkit functions.
When the handle to the TWAIN session is no longer needed, free it by calling L_TwainEndSession. Every call to L_TwainInitSession2 requires a call to L_TwainEndSession when the session is no longer needed.
When passing LTWAIN_INIT_USE_THUNKSERVER to uFlags, it detects and interacts with a 32-bit TWAIN driver or device from a 64-bit process application.
Pass this value only when using a TWAIN device that does not have a 64-bit driver and the operating system is 64-bit. When using the THUNK server be sure to include in the distributables for the application all dependency files listed in the Using the LEADTOOLS THUNK Utility with TWAIN.
LEADTOOLS TWAIN toolkits support both the TWAIN 1.9 and the TWAIN 2.x specifications. By default the toolkit will check whether the current selected TWAIN data source is TWAIN 2.x compliant and try to load the TWAIN 2.x DLL (TWAINDSM.DLL) if it exists in the system. The TWAIN version will be TWAIN_VERSION2".
If that fails or if the scanner is not compatible with TWAIN 2.x, the toolkit will try to start TWAIN 1.9 (Twain_32.DLL) from your system. The TWAIN version will be TWAIN_VERSION1".
You can also override the default behavior and explicitly set which version of TWAIN the selected device will use. To do so, call L_TwainSetVersion and pass “TWAIN_VERSION1” to use version 1.9, or “TWAIN_VERSION2” to use version 2.x. For more information, refer to Setting which TWAIN Specification Version to use and Managing the TWAIN Source.
Call L_TwainGetVersion to determine which TWAIN specification is currently being used by the LEADTOOLS TWAIN toolkit.
Required DLLs and Libraries
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files to be Included with your Application.
|Functions:||L_TwainEndSession, L_TwainInitSession, L_TwainGetVersion, L_TwainSetVersion|
|Topics:||Initializing a TWAIN Session|
|TWAIN Functionality: Session Functions|
|Programming with the LEADTOOLS TWAIN Functions|
|Using LEADTOOLS THUNK Utility with TWAIN|
|Setting which TWAIN Specification Version to use|
L_INT TwainInitSession2Example(HWND hWnd,HBITMAPLIST hBitmap)
HTWAINSESSION hSession = NULL;
/* Check to see if TWAIN is installed */
bAvailable = L_IsTwainAvailable(hWnd);
AppData.hWnd = hWnd;
AppData.uStructSize = sizeof(APPLICATIONDATA);
lstrcpy (AppData.szManufacturerName, TEXT("LEAD Technologies, Inc."));
lstrcpy (AppData.szAppProductFamily, TEXT("LEAD Test Applications"));
lstrcpy (AppData.szVersionInfo, TEXT("Version 1.0"));
lstrcpy (AppData.szAppName, TEXT("TWAIN Test Application"));
nRet = L_TwainInitSession2(&hSession, &AppData, LTWAIN_INIT_MULTI_THREADED);
if (nRet != SUCCESS)
nRet = L_TwainAcquireList(hSession, hBitmap, NULL, LTWAIN_SHOW_USER_INTERFACE);
if(nRet != SUCCESS)
nRet = L_TwainEndSession(&hSession);
if(nRet != SUCCESS)