Performing Basic Print Management Example for C++ 6.0 and later

void PerformBasicPM()
{
   ILEADDicomPrintSCUPtr spPrintSCU(__uuidof(LEADDicomPrintSCU));

   // The sink
   //CPrintSCUSink PrintSCUSink(spPrintSCU);

   spPrintSCU->Timeout = 60; // seconds

   char szMsg[32];

   // Establish the Association
   short nRet = spPrintSCU->Associate("10.0.2.20", 7104, "PrintSCP", "PrintSCU",
                                      DicomClassEnum(
                                      PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS +
                                      PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS +
                                      PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS +
                                      PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS +
                                      PRNSCU_PRESENTATION_LUT_SOP_CLASS +
                                      PRNSCU_PRINT_JOB_SOP_CLASS +
                                      PRNSCU_PRINTER_CONFIGURATION_RETRIEVAL_SOP_CLASS));
   if (nRet == DICOM_ERROR_PRINTSCU_ASSOCIATE_RQ_REJECTED)
   {
      wsprintf(szMsg, "Source = %hd, Reason = %hd",
               spPrintSCU->AssociateRejectSource, spPrintSCU->AssociateRejectReason);
      MessageBox(NULL, szMsg, "Association Request was Rejected", MB_OK);
      return;
   }
   else if (nRet != DICOM_SUCCESS)
   {
      wsprintf(szMsg, "Error code: %hd", nRet);
      MessageBox(NULL, szMsg, "Failed to Establish the Association", MB_OK);
      return;
   }

   // Abort the Association if none of the Basic Print Management Meta SOP Classes
   // is supported on the Association
   if (!spPrintSCU->IsClassSupported (PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS) &&
       !spPrintSCU->IsClassSupported(PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS))
   {
      spPrintSCU->AbortAssociation();
      return;
   }

   // Display some printer info
   //GetPrinterInfo(spPrintSCU->Printer);

   // Display some printer configuration info
   //GetPrinterConfigInfo(spPrintSCU->PrinterConfiguration);

   ILFilmSessionPtr spFilmSession = spPrintSCU->FilmSession;
   ILFilmBoxPtr spFilmBox = spPrintSCU->FilmBox;

   // Create a Film Session
   spFilmSession->IncludedParameters = FilmSessionParameterEnum(0);
   spFilmSession->Create(VARIANT_FALSE);
   MessageBox(NULL, spFilmSession->SOPInstanceUID, "Film Session SOP Instance UID", MB_OK);

   // Update the Number of Copies and Print Priority of the Film Session
   spFilmSession->IncludedParameters = FilmSessionParameterEnum(FS_NUMBER_OF_COPIES +
                                                                FS_PRINT_PRIORITY);
   spFilmSession->NumberOfCopies = 1;
   spFilmSession->PrintPriority = "MED";
   spFilmSession->Update ();

   spFilmBox->IncludedParameters = FilmBoxParameterEnum(0);

   if (spPrintSCU->IsClassSupported(PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS))
   {
      spFilmBox->IncludedParameters = FilmBoxParameterEnum(spFilmBox->IncludedParameters +
                                                           FB_ANNOTATION_DISPLAY_FORMAT_ID);
      spFilmBox->AnnotationDisplayFormatID = "SomeID";
   }

   // Create a Film Box
   spFilmBox->Create("STANDARD\\1,1");
   MessageBox(NULL, spFilmBox->SOPInstanceUID, "Film Box SOP Instance UID", MB_OK);

   _bstr_t sPresLUTInstanceUID;

   // Create a Presentation LUT
   if (spPrintSCU->IsClassSupported (PRNSCU_PRESENTATION_LUT_SOP_CLASS))
   {
      if (spPrintSCU->PresentationLUT->Create("C:\\PresLUT.dic", "") == DICOM_SUCCESS)
      {
         sPresLUTInstanceUID = spPrintSCU->PresentationLUT->GetSOPInstanceUID();
         MessageBox(NULL, sPresLUTInstanceUID, "Pres LUT SOP Instance UID", MB_OK);
      }
   }
   if (sPresLUTInstanceUID.length())
   {
      // Update the Film Box to reference the Presentation LUT we just created
      spFilmBox->IncludedParameters = FB_REF_PRES_LUT_INSTANCE_UID;
      spFilmBox->RefPresLUTInstanceUID = sPresLUTInstanceUID;
      spFilmBox->Update ();
   }

   _bstr_t sOverlayBoxInstanceUID;

   // Create an Image Overlay Box
   if (spPrintSCU->IsClassSupported(PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS))
   {
      spPrintSCU->ImageOverlayBox->OverlayOriginRow = 1;
      spPrintSCU->ImageOverlayBox->OverlayOriginColumn = 1;

      spPrintSCU->ImageOverlayBox->IncludedParameters = OverlayBoxParameterEnum(0);

      if (spPrintSCU->ImageOverlayBox->Create ("C:\\Overlay.dic") == DICOM_SUCCESS)
      {
         sOverlayBoxInstanceUID = spPrintSCU->ImageOverlayBox->GetSOPInstanceUID ();
         MessageBox(NULL, sOverlayBoxInstanceUID, "Image Overlay Box SOP Instance UID", MB_OK);
      }
   }

   // Update the Image Box. Since the Image Display Format of the Film Box was
   // set to "STANDARD\1,1", then we are supposed to have one Image Box created
   // by the Print SCP.
   if (spPrintSCU->ImageBoxes->Count > 0)
   {
      ILImageBoxPtr spImageBox = spPrintSCU->ImageBoxes->Item(0);

      MessageBox(NULL, spImageBox->SOPInstanceUID, "Image Box SOP Instance UID", MB_OK);

      spImageBox->IncludedParameters = ImageBoxParameterEnum(0);

      if (sOverlayBoxInstanceUID.length())
      {
         spImageBox->IncludedParameters = ImageBoxParameterEnum(spImageBox->IncludedParameters +
                                                                IB_REF_IMAGE_OVERLAY_BOX_INSTANCE_UID);
         spImageBox->RefImageOverlayBoxInstanceUID = sOverlayBoxInstanceUID;
      }

      spImageBox->Update("C:\\Image.dic");
   }

   // Update the Annotation Boxes (if there are any)
   long lAnnBoxesCount = spPrintSCU->AnnotationBoxes->Count;
   for (long i = 0; i < lAnnBoxesCount; i++)
   {
      spPrintSCU->AnnotationBoxes->Item(i)->TextString = "Some Text";
      spPrintSCU->AnnotationBoxes->Item(i)->Update(VARIANT_TRUE);
   }

   // Change the Overlay Origin of the Image Overlay Box referenced by the
   // Image Box
   if (sOverlayBoxInstanceUID.length())
   {
      spPrintSCU->ImageOverlayBox->IncludedParameters = OB_OVERLAY_ORIGIN;
      spPrintSCU->ImageOverlayBox->OverlayOriginRow = 10;
      spPrintSCU->ImageOverlayBox->OverlayOriginColumn = 10;

      spPrintSCU->ImageOverlayBox->Update(sOverlayBoxInstanceUID);
   }

   _bstr_t sPrintJobInstanceUID;

   // Print the Film Session (or the Film Box; there is no difference since we
   // have a single Film Box in the Film Session)
   if (TRUE)
   {
      spFilmSession->PrintSession();
      sPrintJobInstanceUID = spFilmSession->PrintJobSOPInstanceUID;
   }
   else
   {
      spFilmBox->PrintBox();
      sPrintJobInstanceUID = spFilmBox->PrintJobSOPInstanceUID;
   }

   // Display some info about the Print Job
   if (spPrintSCU->IsClassSupported(PRNSCU_PRINT_JOB_SOP_CLASS))
   {
      //GetPrintJobInfo(spPrintSCU->PrintJob, sPrintJobInstanceUID);
   }

   // Delete the Film Box (anyway, it would be deleted when the Film Session
   // is deleted)
   spFilmBox->Delete();

   // Delete the Film Session
   spFilmSession->Delete();

   // Delete the Presentation LUT
   if (sPresLUTInstanceUID.length())
   {
      spPrintSCU->PresentationLUT->Delete(sPresLUTInstanceUID);
   }

   // Delete the Image Overlay Box
   if (sOverlayBoxInstanceUID.length())
   {
      spPrintSCU->ImageOverlayBox->Delete(sOverlayBoxInstanceUID);
   }

   // Release the Association and close the connection
   spPrintSCU->ReleaseAssociation();
}