#include "ltwrappr.h"

static L_INT LFileSettings::SetDecryptOptions(pOptions)

Sets the file options used by LEADTOOLS when loading encrypted files.



Pointer to a structure that contains the options used when loading encrypted files.


Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


The values set by this function are valid only for the current thread. To change the values used by the current thread, this function must be called again from that thread.

These settings are used for loading all encrypted files (DOC, DOCX, PDF, PPT, PPTX, XLS, XLSX, etc). An additional password can be provided for loading encrypted PDF files using LFileSettings::SetPDFOptions.

The following scenarios are possible when loading encrypted files:

To get the current options used when loading encrypted files, call LFileSettings::GetDecryptOptions.

Required DLLs and Libraries


Win32, x64.

See Also




static L_INT EXT_CALLBACK GetPasswordProc(const L_TCHAR* pszFileName, L_TCHAR** ppszPassword, L_VOID* pUserData) 
   /* A proper implementation would bring up a message box asking the user "please provide a password for the file 'pszFileName'" */ 
   /* We will keep it simple and hardcode a password, but we will need to prevent an infinite loop. So we will not provide the same password more than once for the same file */ 
   static L_TCHAR szOldFileName[L_MAXPATH]; 
   if (!_tcscmp(pszFileName, szOldFileName)) 
      return ERROR_INV_PASSWORD; /* I already tried this password for this file */ 
   L_TCHAR* pszMyPassword = L_TEXT("Excel"); 
   L_INT nRet = LBase::AllocBuffer((_tcslen(pszMyPassword) + 1) * sizeof(L_TCHAR), (L_VOID**)ppszPassword); 
   if (nRet == SUCCESS) 
      memcpy(*ppszPassword, pszMyPassword, (_tcslen(pszMyPassword) + 1) * sizeof(L_TCHAR)); 
      _tcscpy_s(szOldFileName, _countof(szOldFileName), pszFileName); /* store the filename to indicate that we already provided the password for this filename */ 
   return nRet; 
L_INT TestLoadEncrypted(LBitmapBase* pLBitmap) 
   /* This is an encrypted Excel file which requires the password 'Excel' to load properly */ 
   L_TCHAR* pszFileName = L_TEXT("Encrypted - Encrypted Excel.xlsx"); 
   /* Provide a default password 'DefaultPassword'. If this is not valid, call the GetPasswordProc function */ 
   LFileSettings::GetDecryptOptions(&options, sizeof(FILEDECRYPTOPTIONS)); 
   options.pszPassword = L_TEXT("DefaultPassword"); 
   options.pfnCallback = GetPasswordProc; 
   options.pUserData = NULL; 
   LFile file(pLBitmap, pszFileName); 
   FILEINFO fileInfo = { sizeof(FILEINFO) }; 
   L_INT nRet; 
   if ((nRet = file.GetInfo(&fileInfo, sizeof(FILEINFO), 0, NULL)) != SUCCESS) 
      return nRet; 
   return file.Load(0, ORDER_BGRORGRAY, NULL, &fileInfo); 
Help Version 22.0.2021.9.12
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help