#include "ltwrappr.h"

L_INT LFile::ReadCommentOffset(fd, nOffsetBegin, nBytesToLoad, uType, pComment, uLength, pLoadOptions)

Reads a comment from a file and lets you specify the location of the image data within the file. This enables you to read comments from an image file that is embedded in another file.



The Windows file handle of the file to load.

L_OFFSET nOffsetBegin

The position, from the beginning of the file, of the first byte to load.

L_OFFSET nBytesToLoad

The size of the embedded image file. (The embedded file may be a record within the larger file, and in such cases, this is the record size.)

L_UINT uType

The type of comment. For a list of possible values, refer to Types of File Comments.

L_UCHAR * pComment

Pointer to the buffer that will hold the comment field, including the terminating NULL. Pass NULL to get only the length of the field (the return value).

L_UINT uLength

The size of the buffer that will hold the comment field.


Pointer to optional extended load options. Pass NULL to use the default load options.


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


Like the LFile::ReadComment function, this function lets you read comments that are already saved in a file header. The only difference between the LFile::ReadComment function and this function is that this function allows you to specify an offset for the image data. For more information refer to the LFileSettings::SetComment function.

The location of the image is specified as shown in the following simple illustration:


You must open the file and get a Windows file handle before calling this function. Redirected input (specified with LBaseFile::EnableRedirectIO) is disabled when this function is executing.

Some file formats can contain comments, and some cannot, and each file format has its own set of comment types. When you save a file, the comments, which LEADTOOLS maintains in a global array, are saved in the file. The index into the array (specified using a constant) determines the type of comment, as described in Types of File Comments.

Before saving a file, use the LFileSettings::SetComment function to specify the comments to be saved.

Note: More options are available in the LOADFILEOPTION structure.

Required DLLs and Libraries


Win32, x64.

See Also




The following sample will create a file with an offset and will read a comment from the file it just saved:

#define COMMENT TEXT("I am the artist!") 
L_INT LFile__ReadCommentOffsetExample()  
   LBitmap Bitmap; 
   LFile lf; 
   L_HFILE OffsetFile; /* File handle */ 
   L_OFFSET SizeWritten; /* Variable to be updated with the size written */ 
   L_INT nRet = 0 ; /* Return value */ 
   DWORD wWriteBytes; 
   /* Load an existing bitmap */ 
   nRet = Bitmap.Load(MAKE_IMAGE_PATH(TEXT("eye.gif")), 0, ORDER_BGR); 
   if(nRet != SUCCESS) 
      MessageBox(NULL, TEXT("Load has failed!"), TEXT("FAILURE"), MB_OK|MB_ICONERROR); 
      return nRet; 
   lf.SetBitmap(&Bitmap) ; 
   lf.SetFileName(MAKE_IMAGE_PATH(TEXT("eye.gif"))) ; 
   /* Write some text in the file -- 29 characters and a terminator */ 
   WriteFile(OffsetFile, TEXT("This is a 29-character string"), 30, &wWriteBytes, NULL); 
   /* set and save a comment into a file with an offset */ 
   nRet = LFileSettings::SetComment(CMNT_SZARTIST, (L_UCHAR *)COMMENT, sizeof(COMMENT)); 
   if(nRet < SUCCESS) 
      return nRet; 
   /* Save the image file with an offset inside the TOFFSET.TST file */ 
   nRet = lf.SaveOffset(OffsetFile, 30, &SizeWritten, FILE_TIF); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Close the file */ 
   /* free the bitmap */ 
   nRet = Bitmap.Free(); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Notify the user with a message box */ 
   if (nRet != SUCCESS) 
      MessageBox (NULL, TEXT("Error saving file"), TEXT("Error"), MB_OK); 
      return nRet; 
   /***** Now load the file we just saved ****/ 
   /* Open the file and get the file handle */ 
   /* Get the comment size */ 
   nRet = lf.ReadCommentOffset( OffsetFile, 30, (L_INT)SizeWritten, CMNT_SZARTIST, NULL, 0, NULL); 
   if(nRet >= SUCCESS) 
      /* Allocate a buffer for the comment. Allocate extra byte for string terminator */ 
      L_UCHAR *pComment = (L_UCHAR *)malloc(nRet + 1); 
      nRet =lf.ReadCommentOffset(OffsetFile, 30, (L_INT)SizeWritten, CMNT_SZARTIST, pComment, nRet + 1, NULL); 
      if(nRet > 0) 
         /* make sure the string is NULL-terminated */ 
         pComment[nRet] = 0; 
         /* convert the string to UNICODE and display it */ 
   /* Close the file */ 
   return SUCCESS; 

Help Version 21.0.2021.4.8
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help