Ejemplo n.º 1
0
    /// <summary>
    ///passing SafeFileHandle subclass parameters to unmanaged code in various combinations and forms;
    ///it uses the PInvoke signatures defined above it
    ///1-passing SafeFileHandle subclass parameters individually in separate methods (In, out, ref)
    ///2-passing SafeFileHandle subclass parameters in combination in the same method
    /// </summary>
    public static void RunChildSHParamTests()
    {
        Console.WriteLine("\nRunChildSHParamTests():");

        //1-passing SafeFileHandle subclass parameters individually in separate methods (In, out, ref)

        //get a new SH
        ChildSafeFileHandle hnd = Helper.NewChildSFH();
        Int32 hndInt32          = Helper.SHInt32(hnd); //get the 32-bit value associated with hnd

        Console.WriteLine("Testing SHParam_In...");
        Assert.IsTrue(SHParam_In(hnd, hndInt32), "FAILED! SHParam_In did not receive hnd as expected.");
        //check that the value of the HANDLE did not change
        Assert.IsFalse(Helper.IsChanged(hnd), "FAILED! SHParam_In did not return hnd as expected.");

        Console.WriteLine("Testing SHParam_Out...");
        ChildSFH_NoCloseHandle hndout;

        SHParam_Out(out hndout);
        //check that the value of the HANDLE changed
        Assert.IsTrue(Helper.IsChanged(hndout), "FAILED! SHParam_Out did not return hndout as expected.");

        Console.WriteLine("Testing SHParam_OutRetVal...");
        hndout = null;
        hndout = SHParam_OutRetVal();
        //check that the value of the HANDLE changed
        Assert.IsTrue(Helper.IsChanged(hndout), "FAILED! SHParam_OutRetVal did not return hndout as expected.");

        hndout   = Helper.NewChildSFH_NoCloseHandle(); //get a new value
        hndInt32 = Helper.SHInt32(hndout);
        Console.WriteLine("Testing SHParam_Ref...");
        Assert.IsTrue(SHParam_Ref(ref hndout, hndInt32), "FAILED! SHParam_Ref did not receive hndout as expected.");
        //check that the value of the HANDLE changed
        Assert.IsTrue(Helper.IsChanged(hndout), "FAILED! SHParam_Ref did not return hndout as expected.");

        //2-passing SafeFileHandle subclass parameters in combination in the same method

        //initialize parameters
        ChildSafeFileHandle hnd1 = Helper.NewChildSFH();
        Int32 hnd1Int32          = Helper.SHInt32(hnd1); //get the 32-bit value associated with hnd1

        ChildSFH_NoCloseHandle hnd2 = null;              //out parameter

        ChildSFH_NoCloseHandle hnd3 = Helper.NewChildSFH_NoCloseHandle();
        Int32 hnd3Int32             = Helper.SHInt32(hnd3); //get the 32-bit value associated with hnd3

        Console.WriteLine("Testing SHParam_Multiple...");
        Assert.IsTrue(SHParam_Multiple(hnd1, out hnd2, ref hnd3, hnd1Int32, hnd3Int32), "FAILED! SHParam_Multiple did not receive parameter(s) as expected.");
        //check that the value of the HANDLES are as expected
        Assert.IsFalse(Helper.IsChanged(hnd1), "FAILED! SHParam_Multiple did not return handle:hnd1 as expected.");
        Assert.IsTrue(Helper.IsChanged(hnd2), "FAILED! SHParam_Multiple did not return handle:hnd2 as expected.");
        Assert.IsTrue(Helper.IsChanged(hnd3), "FAILED! SHParam_Multiple did not return handle:hnd3 as expected.");
    }
Ejemplo n.º 2
0
 public static extern bool SHParam_Multiple([In] ChildSafeFileHandle sh1, out ChildSFH_NoCloseHandle sh2, ref ChildSFH_NoCloseHandle sh3, Int32 sh1Value, Int32 sh3Value);
Ejemplo n.º 3
0
 public static extern bool SHParam_In([In] ChildSafeFileHandle sh1, Int32 sh1Value);