Comment example for C++ 4.0 and later

This example does the following:

1. Loads an image from a TIFF file.

2. Updates the current comment array by reading comments from the file.

3. Modifies one of the comments.

4. Modifies and saves the file.

5. Reads the comment that was saved, and displays it in a message box.

This example handles only string comments. For more complex comments, refer to Exif Examples.

// Value for clearing comments.
COleVariant Empty = COleVariant();

// Specify the file that we will load and update.
CString FilePath = "d:\\lead\\images\\testcmt.tif";

// Get all of the current comments from the file.
// Temporarily disable errors so that we do not fail when comments are missing.
m_Lead1.SetEnableMethodErrors(FALSE);
for(short i = 0; i <= CMNT_LAST; ++i)
{
  m_Lead1.SetComment(i, Empty);
  m_Lead1.SetComment(i, m_Lead1.ReadComment(FilePath, 0, i));
}
m_Lead1.SetEnableMethodErrors(TRUE);

// Load and modify the image.
m_Lead1.Load(FilePath, 0, 0, 1);
m_Lead1.Reverse();

// Update the CMNT_SZDESC comment.
VARIANT V1 = m_Lead1.GetComment(CMNT_SZDESC);
COleVariant VDescString;
VDescString.Attach(V1);
VDescString =  CString(VDescString.bstrVal) + "\nThis image has been reversed.";
m_Lead1.SetComment(CMNT_SZDESC, VDescString);

// Save the file.
int SaveBits = m_Lead1.GetBitmapBits();
m_Lead1.Save(FilePath, FILE_EXIF, SaveBits, 0, SAVE_OVERWRITE);

// Read the comment that we saved.
VARIANT V2 = m_Lead1.ReadComment(FilePath, 0, CMNT_SZDESC);
COleVariant VNewDescString;
VNewDescString.Attach(V2);

// Display the message.
MessageBox(CString(VNewDescString.bstrVal));

// Clear the comments from memory
for( i = 0; i <= CMNT_LAST; ++i)
  m_Lead1.SetComment(i, Empty);