L_TwainAddCapabilityToFile

#include "lttwn.h"

L_LTTWN_API L_INT L_TwainAddCapabilityToFile (hSession, hFile, pCapability )

Adds a capability to a file.

Parameters

HTWAINSESSION hSession

Handle to an existing TWAIN session. This handle is obtained by calling the L_TwainInitSession or L_TwainInitSession2 function.

HTWAINTEMPLATEFILE hFile

Handle to an existing template file.

pTW_CAPABILITY pCapability

Pointer to a structure that contains the capability to add.

Returns

Value Meaning
SUCCESS The function was successful.
! = SUCCESS An error occurred. Refer to Return Codes.

Comments

In order to add a capability to a template file, the template file must first be opened for writing using L_TwainOpenTemplateFile. Opening the file for writing will create a new empty file. Capabilities are added to the file sequentially. When all capabilities have been added, save the file by calling L_TwainCloseTemplateFile. For more information on capabilities, refer to Getting and Setting Capabilities.

For more information on Template files, refer to Handling Template Files.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT CALLBACK SaveCapsCB (HTWAINSESSION  hSession, 
                           L_UINT         uCap, 
                           pTW_CAPABILITY pCapability, 
                           L_VOID      * pUserData) 
{ 
   UNREFERENCED_PARAMETER(uCap); 
 
   L_INT nRet; 
   HTWAINTEMPLATEFILE hFile = NULL; 
 
   if (!pUserData) 
      return SUCCESS; 
 
   hFile = (HTWAINTEMPLATEFILE)pUserData; 
   if (!pCapability) 
      return SUCCESS; 
 
   if (!pCapability->hContainer) 
      GlobalFreePtr (pCapability); 
 
   nRet = L_TwainAddCapabilityToFile (hSession, hFile, pCapability); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   GlobalFree (pCapability->hContainer); 
   return SUCCESS; 
} 
 
L_INT TwainAddCapabilityToFileExample(HWND               hDlg, // Parent dialog handle 
                                                       HTWAINTEMPLATEFILE hFile, 
                                                       HTWAINSESSION g_hSession) 
{ 
 
   L_INT nRet; 
   OPENFILENAME ofn; 
   L_TCHAR szFilePath[MAX_PATH]; 
 
 
   memset (&ofn, 0, sizeof(OPENFILENAME)); 
   memset (szFilePath, 0, MAX_PATH); 
   ofn.lStructSize = sizeof(OPENFILENAME); 
   ofn.hwndOwner = hDlg; 
   ofn.lpstrFile = szFilePath; 
   ofn.nMaxFile = MAX_PATH; 
   ofn.lpstrFilter = TEXT("LEAD TWAIN TEMPLATE\0*.ltt\0All Files\0*.*\0\0"); 
   ofn.lpstrDefExt = TEXT("ltt"); 
   ofn.lpstrTitle = TEXT("Save Template File"); 
   ofn.Flags       = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; 
 
   if (GetSaveFileName (&ofn)) 
   { 
      nRet = L_TwainOpenTemplateFile (g_hSession, &hFile, szFilePath, LTWAIN_TEMPLATE_OPEN_WRITE); 
      if (nRet == SUCCESS) 
      { 
         nRet = L_TwainStartCapsNeg(g_hSession); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_TwainEnumCapabilities (g_hSession, SaveCapsCB, LTWAIN_CAPABILITY_GETCURRENT, hFile); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_TwainCloseTemplateFile (g_hSession, hFile); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_TwainEndCapsNeg(g_hSession); 
         if(nRet != SUCCESS) 
            return nRet; 
      } 
      else 
         return nRet; 
   } 
   return SUCCESS; 
} 
Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS TWAIN C API Help