/// <summary> ///passing SH subclass parameters to unmanaged code in various combinations and forms; ///it uses the PInvoke signatures defined above it ///1- passing SH subclass parameters individually in separate methods (In, out, ref) ///2- passing SH subclass parameters in combination in the same method /// </summary> public static void RunSHParamTests() { Console.WriteLine("SHParam_In"); SafeFileHandle hnd = Helper.NewSFH(); //get a new SH Int32 hndInt32 = Helper.SHInt32(hnd); //get the 32-bit value associated with hnd Assert.IsTrue(SHParam_In(hnd, hndInt32), "SHParam_In did not receive hnd as expected"); Assert.IsTrue(!Helper.IsChanged(hnd), "SHParam_In did not return hnd as expected."); Console.WriteLine("SHParam_Out"); SFH_NoCloseHandle hndout; SHParam_Out(out hndout); Assert.IsTrue(Helper.IsChanged(hndout), "SHParam_Out did not return hndout as expected. hndout = " + Helper.SHInt32(hndout)); Console.WriteLine("SHParam_OutRetVal"); hndout = null; hndout = SHParam_OutRetVal(); Assert.IsTrue(Helper.IsChanged(hndout), "SHParam_OutRetVal did not return hndout as expected."); Console.WriteLine("SHParam_Ref"); hndout = Helper.NewSFH_NoCloseHandle(); //get a new value hndInt32 = Helper.SHInt32(hndout); Assert.IsTrue(SHParam_Ref(ref hndout, hndInt32), "SHParam_Ref did not receive hndout as expected"); Assert.IsTrue(Helper.IsChanged(hndout), "SHParam_Ref did not return hndout as expected."); Console.WriteLine("SHParam_Multiple"); SafeFileHandle hnd1 = Helper.NewSFH(); Int32 hnd1Int32 = Helper.SHInt32(hnd1); //get the 32-bit value associated with hnd1 SFH_NoCloseHandle hnd2 = null; //out parameter SFH_NoCloseHandle hnd3 = Helper.NewSFH_NoCloseHandle(); Int32 hnd3Int32 = Helper.SHInt32(hnd3); //get the 32-bit value associated with hnd3 Assert.IsTrue(SHParam_Multiple(hnd1, out hnd2, ref hnd3, hnd1Int32, hnd3Int32), "SHParam_Multiple did not receive parameter(s) as expected."); Assert.IsTrue(Helper.IsChanged(hnd2), "HParam_Multiple did not return hnd2 as expected."); Assert.IsTrue(Helper.IsChanged(hnd3), "HParam_Multiple did not return hnd3 as expected."); }
/// <summary> ///passing SH subclass parameters to unmanaged code in various combinations and forms; ///it uses the PInvoke signatures defined above it ///1- passing SH subclass parameters individually in separate methods (In, out, ref) ///2- passing SH subclass parameters in combination in the same method /// </summary> public static void RunSHParamTests() { Console.WriteLine("\nRunSHParamTests():"); ///1- passing SH subclass parameters individually in separate methods (In, out, ref) //get a new SH SafeFileHandle hnd = Helper.NewSFH(); Int32 hndInt32 = Helper.SHInt32(hnd); //get the 32-bit value associated with hnd Console.WriteLine("Testing SHParam_In..."); SHParam_In(hnd, hndInt32); CheckCleanUp(hnd); SFH_NoCloseHandle hndout = Helper.NewSFH_NoCloseHandle(); //get a new value SafeHandle hnd_ref_backup = hndout; hndInt32 = Helper.SHInt32(hndout); Console.WriteLine("Testing SHParam_Ref..."); SHParam_Ref(ref hndout, hndInt32); CheckCleanUp(hnd_ref_backup); ///2- passing SH subclass parameters in combination in the same method //initialize parameters SafeFileHandle hnd1 = Helper.NewSFH(); Int32 hnd1Int32 = Helper.SHInt32(hnd1); //get the 32-bit value associated with hnd1 SFH_NoCloseHandle hnd2 = null; //out parameter SFH_NoCloseHandle hnd3 = Helper.NewSFH_NoCloseHandle(); SafeHandle hnd3_ref_backup = hnd3; Int32 hnd3Int32 = Helper.SHInt32(hnd3); //get the 32-bit value associated with hnd3 Console.WriteLine("Testing SHParam_Multiple..."); SHParam_Multiple(hnd1, out hnd2, ref hnd3, hnd1Int32, hnd3Int32); CheckCleanUp(hnd1); CheckCleanUp(hnd2); CheckCleanUp(hnd3_ref_backup); }
public static extern bool SHMixedParam1(SafeHandle sh1, out SFH_NoCloseHandle sh2, ref ChildSFH_NoCloseHandle sh3, StructWithBaseSHFld s1, StructWithSHFld s2, ref StructWithChildSHFld s3, Int32 sh1Value, Int32 sh3Value, Int32 s1fldValue, Int32 s2fldValue, Int32 s3fldValue);
public static extern bool SHParam_Multiple([In] SafeFileHandle sh1, out SFH_NoCloseHandle sh2, ref SFH_NoCloseHandle sh3, Int32 sh1Value, Int32 sh3Value);
public static extern bool SHParam_Ref(ref SFH_NoCloseHandle sh1, Int32 sh1Value);
public static extern bool SHParam_Out(out SFH_NoCloseHandle sh1);