Пример #1
0
    static int Main()
    {
        SomeTestStruct_Auto someTs_Auto = new SomeTestStruct_Auto();

        try
        {
            Marshal.StructureToPtr(someTs_Auto, new IntPtr(123), true);
        }
        catch (ArgumentException ex)
        {
            if (ex.ParamName != "structure")
            {
                Console.WriteLine("Thrown ArgumentException is incorrect.");
                return(103);
            }
            if (!ex.Message.Contains("The specified structure must be blittable or have layout information."))
            {
                Console.WriteLine("Thrown ArgumentException is incorrect.");
                return(104);
            }
            return(100);
        }
        catch (Exception e)
        {
            Console.WriteLine("Marshal.StructureToPtr threw unexpected exception {0}.", e);
            return(102);
        }
        Console.WriteLine("Marshal.StructureToPtr did not throw an exception.");
        return(101);
    }
Пример #2
0
 static int Main()
 {
   SomeTestStruct_Auto someTs_Auto = new SomeTestStruct_Auto();
   try
   {
     Marshal.StructureToPtr(someTs_Auto, new IntPtr(123), true);
   }
   catch (ArgumentException ex)
   {
     if (ex.ParamName != "structure")
     {
       Console.WriteLine("Thrown ArgumentException is incorrect.");
       return 103;
     }
     if (!ex.Message.Contains("The specified structure must be blittable or have layout information."))
     {
       Console.WriteLine("Thrown ArgumentException is incorrect.");
       return 104;
     }
     return 100;
   }
   catch (Exception e)
   {
     Console.WriteLine("Marshal.StructureToPtr threw unexpected exception {0}.", e);
     return 102;
   }
   Console.WriteLine("Marshal.StructureToPtr did not throw an exception.");
   return 101;
 }