New test.
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ImageCodecInfo.cs
index 9acb4236407762cb1a3984de3930ac22afea98b5..ecdc66b5760952cc609ec7bdb9e940695ed00e77 100644 (file)
 //   Jordi Mas i Hernandez (jordi@ximian.com)
 //
 // (C) 2002 Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Runtime.InteropServices;
 using System.Collections;
 using System.IO;
 
 namespace System.Drawing.Imaging {
 
+#if ONLY_1_1
        [ComVisible (false)]
-       public sealed class ImageCodecInfo 
-       {
+#endif
+       public sealed class ImageCodecInfo {
                private Guid clsid;
                private string codecName;
                private string dllName;
@@ -80,21 +77,23 @@ namespace System.Drawing.Imaging {
                                return result;                  
                        
                        /* Get decoders list*/
-                       decoders = Marshal.AllocHGlobal (arraySize);                                            
-                       status = GDIPlus.GdipGetImageDecoders (decoderNums,  arraySize, decoders);
-                       GDIPlus.CheckStatus (status);
-                       
-                       decoder_size = Marshal.SizeOf (gdipdecoder);                    
-                       decoder_ptr = decoders;
-                       
-                       for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size))
-                       {
-                               gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));   
-                               result[i] = new ImageCodecInfo ();
-                               GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);                          
+                       decoders = Marshal.AllocHGlobal (arraySize);
+                       try {
+                               status = GDIPlus.GdipGetImageDecoders (decoderNums,  arraySize, decoders);
+                               GDIPlus.CheckStatus (status);
+                       
+                               decoder_size = Marshal.SizeOf (gdipdecoder);
+                               decoder_ptr = decoders;
+                       
+                               for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size)) {
+                                       gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));
+                                       result[i] = new ImageCodecInfo ();
+                                       GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);
+                               }
+                       }
+                       finally {
+                               Marshal.FreeHGlobal (decoders);
                        }
-                       
-                       Marshal.FreeHGlobal (decoders);
                        return result;
                }
                
@@ -117,21 +116,22 @@ namespace System.Drawing.Imaging {
                        
                        /* Get encoders list*/
                        encoders = Marshal.AllocHGlobal (arraySize);
-                       
-                       status = GDIPlus.GdipGetImageEncoders (encoderNums,  arraySize, encoders);
-                       GDIPlus.CheckStatus (status);
-                       
-                       encoder_size = Marshal.SizeOf (gdipencoder);                    
-                       encoder_ptr = encoders;
-                       
-                       for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size))
-                       {
-                               gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));                                           
-                               result[i] = new ImageCodecInfo ();
-                               GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);                          
+                       try {
+                               status = GDIPlus.GdipGetImageEncoders (encoderNums,  arraySize, encoders);
+                               GDIPlus.CheckStatus (status);
+                       
+                               encoder_size = Marshal.SizeOf (gdipencoder);
+                               encoder_ptr = encoders;
+                       
+                               for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size)) {
+                                       gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));
+                                       result[i] = new ImageCodecInfo ();
+                                       GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);
+                               }
+                       }
+                       finally {
+                               Marshal.FreeHGlobal (encoders);
                        }
-                       
-                       Marshal.FreeHGlobal (encoders);
                        return result;
                }