L_TwainAddCapabilityToFile

#include "lttw2.h"

L_INT EXT_FUNCTION L_TwainAddCapabilityToFile (hSession, hFile, ptwCapability)

HTWAINSESSION hSession;

/* handle to an existing TWAIN session */

HTWAINTEMPLATEFILE hFile;

/* handle to an existing template file */

pTW_CAPABILITY ptwCapability;

/* pointer to a structure */

Adds a capability to a file.

Parameter

Description

hSession

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

hFile

Handle to an existing template file.

ptwCapability

Pointer to a structure that contains the capability to add.

Returns

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 the L_TwainOpenTemplateFile. Opening the file for writing will create a new empty file. The process of adding capabilities to the file will add them 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

LTTWN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_TwainOpenTemplateFile, L_TwainTemplateDlg, L_TwainGetCapabilityFromFile, L_TwainGetNumOfCapsInFile, L_TwainCloseTemplateFile, L_TwainInitSession, L_TwainEndSession.

Topics:

Handling Template Files

 

TWAIN Functionality: Capability Functions.

Example

HTWAINSESSION g_hSession;
OPENFILENAME ofn;
L_INT nRet;
HTWAINTEMPLATEFILE hFile;
L_TCHAR szFilePath [MAX_PATH];
HWND hDlg; // Parent dialog handle


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.lpstrTitle = TEXT("Save Template File");

if (GetSaveFileName (&ofn))
{
   nRet = L_TwainOpenTemplateFile (g_hSession, &hFile, szFilePath, LTWAIN_TEMPLATE_OPEN_WRITE);
   if (nRet == SUCCESS)
   {
      L_TwainEnumCapabilities (g_hSession, SaveCapsCB, LTWAIN_CAPABILITY_GETCURRENT, hFile);
      L_TwainCloseTemplateFile (g_hSession, hFile);
   }
}

L_INT CALLBACK SaveCapsCB (HTWAINSESSION hSession, L_UINT uCap, pTW_CAPABILITY pCapability, L_VOID * pUserData)
{
   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);

GlobalFree (pCapability->hContainer);
GlobalFreePtr (pCapability);

return SUCCESS;
}