Ejemplo n.º 1
0
        private static void StructArgument()
        {
            Console.WriteLine("\r\n");
            ManagedSimpleStruct simpleStruct = new ManagedSimpleStruct();

            simpleStruct.intValue    = 10;
            simpleStruct.shortValue  = 20;
            simpleStruct.floatValue  = 3.5f;
            simpleStruct.doubleValue = 6.8f;

            CPlusPlusLib.StructArgumentByVal(simpleStruct);

            Console.WriteLine("\r\n");

            ManagedSimpleStruct argStruct = new ManagedSimpleStruct();

            argStruct.intValue    = 1;
            argStruct.shortValue  = 2;
            argStruct.floatValue  = 3.0f;
            argStruct.doubleValue = 4.5f;
            CPlusPlusLib.StructArgumentByRef(ref argStruct);

            Console.WriteLine("new struct value:int = {0}, short = {1}, float = {2:f6}, double = {3:f6}",
                              argStruct.intValue, argStruct.shortValue, argStruct.floatValue, argStruct.doubleValue);
        }
Ejemplo n.º 2
0
        private static void StructReturn()
        {
            IntPtr pStruct = CPlusPlusLib.ReturnStruct();
            ManagedSimpleStruct retStruct = (ManagedSimpleStruct)Marshal.PtrToStructure(pStruct, typeof(ManagedSimpleStruct));

            Marshal.FreeCoTaskMem(pStruct);

            Console.WriteLine("\nreturn struct value:int = {0}, short = {1}, float = {2:f6}, double = {3:f6}",
                              retStruct.intValue, retStruct.shortValue, retStruct.floatValue, retStruct.doubleValue);

            IntPtr ppStruct = IntPtr.Zero;

            CPlusPlusLib.ReturnStructFromArg(ref ppStruct);
            ManagedSimpleStruct retStructA = (ManagedSimpleStruct)Marshal.PtrToStructure(ppStruct, typeof(ManagedSimpleStruct));

            Marshal.FreeCoTaskMem(ppStruct);

            Console.WriteLine("return struct value:int = {0}, short = {1}, float = {2:f6}, double = {3:f6}",
                              retStruct.intValue, retStruct.shortValue, retStruct.floatValue, retStruct.doubleValue);
        }
Ejemplo n.º 3
0
 public static extern void StructArgumentByRef(ref ManagedSimpleStruct argStruct);
Ejemplo n.º 4
0
 public static extern void StructArgumentByVal(ManagedSimpleStruct argStruct);