Gets a single comment, a group of comments or several groups of comments from a file.


#include "ltwrappr.h"

virtual L_INT LFile::ReadComment(uType, pLBuffer, pLoadFileOption=NULL)


L_UINT uType

The type of comment. Refer to Types of File Comments. A group of comments may be obtained such as CMNT_FPXSUMMARYINFORMATION, or more than one group of comments may be retrieved by using OR as in CMNT_FPXSUMMARYINFORMATION | CMNT_FPXFILESOURCEGROUP, or all comments may be obtained by using CMNT_ALL. See Example listed below. For more information concerning FlashPix file comments, see FlashPix File Comments.

LBuffer * pLBuffer

Pointer to the buffer object that will hold all the comments.


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


Value Meaning
>=0 Length of the comment field.
< 0 An error occurred. Refer to Return Codes.


The basic order of function calls to retrieve comments is as follows:

  1. Get the size of the comments with LFile::GetCommentSize.
  2. Allocate a buffer of a corresponding size.
  3. Read the comments with [LFile:ReadComment.
  4. Free the buffer.

To write comments to a file, all the comments you wish to add to a new file must be set. LFileSettings::SetComment sets each comment individually, but it does not save the comments to the file, it prepares the values for the next save.. Once all comments are set, the comments are saved using any function which saves files, such as LFile::SaveFile or LFile::Save when creating a new file. If you wish to change a comment in an existing file, use LFile::WriteComment.

Required DLLs and Libraries


Win32, x64.

See Also




This example demonstrates all of the functions related to comments for TIFF files.
It clears all comments, sets a new comment, gets the comment from memory,
saves a file with the comment, then gets the comment from the file.

L_INT LFile__ReadCommentExample()  
   L_INT nRet; 
   L_INT CommentLength;  
   LBitmap LeadBitmap; 
   LFileSettings fileSettings; 
   HGLOBAL hTextToGet; 
   L_CHAR *pTextToSet = "Susie, the artist"; 
   L_CHAR *pTextToGet; 
   L_TCHAR message[200];  
   //Set the comment 
   nRet = fileSettings.SetComment(CMNT_SZARTIST, (L_UCHAR *)pTextToSet, (L_INT) (strlen(pTextToSet) + 1)); 
   if(nRet < 0) 
      return nRet; 
   //Get the length of a comment 
   CommentLength = fileSettings.GetComment(CMNT_SZARTIST, NULL, 0); 
   //Allocate and lock a zero-filled buffer for the comment 
   hTextToGet = GlobalAlloc(GPTR, CommentLength); 
   pTextToGet = (L_CHAR *)GlobalLock(hTextToGet); 
   //Get the actual comment 
   fileSettings.GetComment(CMNT_SZARTIST, (L_UCHAR *)pTextToGet, CommentLength); 
   //Show the comment that will be saved 
   wsprintf(message,TEXT(" %hs"),pTextToGet); 
   ::MessageBox(NULL, message, TEXT("Saving Artist Comment"), MB_OK); 
   // Free memory 
   //Load, and then save the image with the new comment 
   nRet = LeadBitmap.Load(); 
   if(nRet != SUCCESS) 
      return nRet; 
   nRet = LeadBitmap.Save(FILE_TIF, 8, 0, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   //Get the length of a comment in the file  
   CommentLength = LeadBitmap.File()->ReadComment(CMNT_SZARTIST, NULL); 
   //Get the actual comment from the file 
   LBuffer LeadBuffer(CommentLength); 
   nRet = LeadBitmap.File()->ReadComment(CMNT_SZARTIST, &LeadBuffer); 
   if(nRet < 1) 
      return nRet; 
   //Show the comment that was saved in the file  
   wsprintf(message,TEXT(" %hs"),LeadBuffer.Lock()); 
   ::MessageBox (NULL, message, TEXT("Artist comment"), MB_OK); 
   return SUCCESS; 

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

LEADTOOLS Raster Imaging C++ Class Library Help