Comment example for C++ 5.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.

ILEADRasterIO *pRasterIO=NULL;
   ILEADRasterProcess *pRasterProc=NULL; 
   ILEADRasterVariant * pltRasVar1 = NULL; 
   ILEADRasterVariant * pltRasVar2 = NULL; 
   ILEADRasterVariant * pltRasVarEmpty = NULL; 

   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, 
                    IID_ILEADRasterIO, (void**)&pRasterIO); 
   CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, 
                    IID_ILEADRasterProcess, (void**)&pRasterProc); 
   CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL, 
                                   IID_ILEADRasterVariant, (void **)&pltRasVar1); 
   CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL, 
                                   IID_ILEADRasterVariant, (void **)&pltRasVar2); 
   CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL, 
                                   IID_ILEADRasterVariant, (void **)&pltRasVarEmpty); 

   
   // Specify the file that we will load and update. 
   CString FilePath = TEXT("d:\\temp\\tmp.tif");
   // Get all of the current comments from the file. 
   // Temporarily disable errors so that we do not fail when comments are missing. 
   pRasterIO->PutEnableMethodErrors(FALSE); 
   for(short i = 0; i <= CMNT_LAST; ++i) 
   {
     pRasterIO->PutComment(i, pltRasVarEmpty); 
     pRasterIO->PutComment(i, 
                           pRasterIO->ReadComment(m_LEADRasterView1.GetRaster(),
                                                  LPCTSTR(FilePath), 1, i)); 
   }
   pRasterIO->PutEnableMethodErrors(TRUE); 
   // Load and modify the image. 
   pRasterIO->Load(m_LEADRasterView1.GetRaster(),
                   LPCTSTR(FilePath), 0, 0, 1); 
   pRasterProc->Reverse(m_LEADRasterView1.GetRaster());
   // Update the CMNT_SZDESC comment. 
   pltRasVar1 = pRasterIO->GetComment(CMNT_SZDESC); 
   pltRasVar1->Type = VALUE_STRING; 
   pltRasVar1->StringValue  =  "\nThis image has been reversed."; 
   pRasterIO->PutComment(CMNT_SZDESC, pltRasVar1); 
   // Save the file. 
   int SaveBits = m_LEADRasterView1.GetRaster().GetBitmapBits();
   pRasterIO->Save(m_LEADRasterView1.GetRaster(),
                   LPCTSTR(FilePath), FILE_EXIF, SaveBits, 
                   (QFactorConstants)0, SAVE_OVERWRITE); 
   // Read the comment that we saved. 
   pltRasVar2 = pRasterIO->ReadComment(m_LEADRasterView1.GetRaster(),
                                       LPCTSTR(FilePath), 1, CMNT_SZDESC); 
   
   // Display the message. 
   MessageBox(pltRasVar2->StringValue); 
   // Clear the comments from memory
   for( i = 0; i <= CMNT_LAST; ++i) 
     pRasterIO->PutComment(i, pltRasVarEmpty); 
   pRasterIO->Release();
   pRasterProc->Release();
   pltRasVar1->Release();
   pltRasVar2->Release();
   pltRasVarEmpty->Release();