Example #1
0
    /// <summary>
    ///runs all other miscellaneous tests;
    ///it uses the PInvoke signatures defined above it
    ///1-passing arrays of SHs as parameters
    ///2-passing arrays of structures (with SH subclass fields) as parameters
    ///3-returning SHs from unmanaged code as pure return values
    ///4-returning structures (with SH subclass fields) from unmanaged code as pure return values
    ///5-passing nested structures (with the nested structure having a SH subclass field)
    ///6-passing structures with SH Array fields
    ///7-passing mixed params (SH, SH subclass, subclass of SH subclass)
    ///8-passing struct params that have many handle fields [in, ref (with and without changes to flds)]
    ///9-passing SH subclass in Dispatch\UnknownWrapper, expecting a VARIANT (of type VT_DISPATCH or
    ///VT_UNKNOWN) on the managed side; as params and as fields
    /// </summary>
    public static void RunSHMiscTests()
    {
        Console.WriteLine("\nRunSHMiscTests():");

        ///1-passing arrays of SHs as parameters

        SafeFileHandle[] hndArray = new SafeFileHandle[Helper.N];
        //the following array will contain the 32-bit values corresponding to hndArray's elements
        Int32[] hndArrayInt32s = new Int32[Helper.N];
        for (int i = 0; i < Helper.N; i++)
        {
            hndArray[i]       = Helper.NewSFH();
            hndArrayInt32s[i] = Helper.SHInt32(hndArray[i]);
        }
        Console.WriteLine("Testing SHArrayParam...");
        Assert.Throws <MarshalDirectiveException>(() => SHArrayParam(hndArray, hndArrayInt32s, Helper.N), "FAILED!  Exception not thrown.");

        //4-returning structures (with SH subclass fields) from unmanaged code as pure return values
        Console.WriteLine("Testing SHReturnStruct...");
        Assert.Throws <MarshalDirectiveException>(() => SHReturnStruct(), "FAILED!  Exception not thrown.");

        //6-passing structures with SH Array fields
        hndArray = new SafeFileHandle[Helper.N];
        //the following array will contain the 32-bit values corresponding to hndArray's elements
        hndArrayInt32s = new Int32[Helper.N];
        for (int i = 0; i < Helper.N; i++)
        {
            hndArray[i]       = Helper.NewSFH();
            hndArrayInt32s[i] = Helper.SHInt32(hndArray[i]);
        }
        StructWithSHArrayFld sWithArrFld = new StructWithSHArrayFld();

        sWithArrFld.sharr = hndArray; //assign hnd array to hnd array field
        Console.WriteLine("Testing SHStructParam_In2...");
        Assert.Throws <TypeLoadException>(() => SHStructParam_In2(sWithArrFld, hndArrayInt32s, Helper.N), "FAILED!  Exception not thrown.");
    }
Example #2
0
 public static extern bool SHStructParam_In2([In] StructWithSHArrayFld s, Int32[] arrInt32s, int length);