AnnEncryptApply example for Visual Basic

Private Sub ExampleEncrypter(hObject As Long)

   Dim ObjectType As AnnObjectType

   RasterAnn.AnnGetType hObject
   ObjectType = RasterAnn.AnnType

   If ObjectType <> ANN_OBJECT_ENCRYPT Then
      MsgBox "This Object is not an Encrypt Object"
   End If

   RasterAnn.AnnEncryptOptions.Flags = ANN_ENCRYPT_ALL
   RasterAnn.AnnGetEncryptOptions hObject

   If  IsNull(RasterAnn.AnnEncryptOptions.EncryptRaster) Then
      MsgBox "The encrypt object is not associated with a bitmap."
      Exit Sub
   End If
   If RasterAnn.AnnEncryptOptions.EnableEncryptor = False Then
      MsgBox "This object is a decryptor"
   End If

   'change the key to 123
   RasterAnn.AnnEncryptOptions.Key = 123
   RasterAnn.AnnEncryptOptions.Flags = ANN_ENCRYPT_KEY
   RasterAnn.AnnEncryptOptions.EnableSaveEncryptorKey = True
   RasterAnn.AnnEncryptOptions.EnableSaveDecryptorKey = True
   RasterAnn.AnnEncryptOptions.EnableClearEncryptorKey = True
   RasterAnn.AnnEncryptOptions.EnableClearDecryptorKey = True
   RasterAnn.AnnEncryptOptions.EnableNeverEncrypted = False
   RasterAnn.Flags = 0
   RasterAnn.AnnSetEncryptOptions hObject

   RasterAnn.AnnEncryptApply hObject, ANN_ENCRYPTAPPLY_ENCRYPTOR

   nRet = MsgBox("Encryptor has been applied.  Would you like to remove the encryption?", vbYesNo)

   If nRet = vbYes Then
      RasterAnn.AnnEncryptApply hObject, ANN_ENCRYPTAPPLY_DECRYPTOR
   End If

End Sub