Gets a comment field from a file in memory.


#include "ltwrappr.h"

virtual L_INT LMemoryFile::ReadComment(LMemoryBuffer, pLCommentBuffer, uType, pLoadFileOption=NULL)


LBuffer& LMemoryBuffer

A LEAD LBuffer object that contains the file in memory.

LBuffer * pLCommentBuffer

A LEAD LBuffer object to be updated with the comment field, including the terminating NULL. You can pass NULL if you only want to get the length of the field (the return value).

L_UINT uType

The type of comment. Refer to Types of File 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.


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, you use the LFileSettings::SetComment function to specify the comments to be saved.

The [LMemoryFile:ReadComment function lets you read comments that are already saved in a file in memory. For more information refer to the LFileSettings::SetComment function.


The LMemoryBuffer parameter is passed by reference, and is a required parameter.

Required DLLs and Libraries


Win32, x64.

See Also




L_INT LMemoryFile__ReadCommentExample() 
   L_INT nRet; 
   L_TCHAR szMessage[80]; // MessageBox string  
   L_INT CommentLength; // Length of the comment string that we will get 
   LMemoryFile LeadMemFile ; 
   LBuffer LeadMemBuffer ; 
   LBuffer LeadCommBuffer ; 
   LFile LeadFile; 
   LBitmapBase LeadBitmap; 
   LFileSettings fileSettings; 
   L_CHAR *pTextToSet = "Susie, the artist"; 
   LeadFile.SetBitmap(&LeadBitmap) ; 
   LeadFile.SetFileName(MAKE_IMAGE_PATH(TEXT("clean.tif"))) ; 
   nRet = LeadFile.Load() ; 
   if(nRet != SUCCESS) 
      return nRet; 
   LeadMemFile.SetBitmap(&LeadBitmap) ; 
   nRet = fileSettings.SetComment(CMNT_SZARTIST, (L_UCHAR *)pTextToSet, (L_INT) (strlen(pTextToSet) + 1)); 
   if(nRet < 1) 
      return nRet; 
   nRet =LeadMemFile.Save(&LeadMemBuffer,FILE_TIF,8,NULL) ; 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Use the return value to get the length of a comment in the file  
   CommentLength = LeadMemFile.ReadComment (LeadMemBuffer, NULL, CMNT_SZARTIST, NULL); 
   if (CommentLength < 0) 
      MessageBox(NULL,TEXT("File has not comment ..."), TEXT("Read Memory Comment"),MB_OK) ; 
      return CommentLength; 
   nRet =LeadCommBuffer.Reallocate((L_INT32)CommentLength); 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Get the actual comment from the file  
   nRet =LeadMemFile.ReadComment ( LeadMemBuffer, &LeadCommBuffer, CMNT_SZARTIST); 
   if(nRet < 0) 
      return nRet; 
   // Show the comment that was saved in the file  
   wsprintf (szMessage, TEXT("ARTIST:\n %hs"), LeadCommBuffer.Lock()); 
   MessageBox (NULL, szMessage, TEXT("ARTIST"), MB_OK); 
   LeadCommBuffer.Unlock() ; 
   return SUCCESS; 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help