public static void Run()
        {
            Console.WriteLine("----- String marshalling samples -----");

            MarshallingSampleNative.CountBytesInString(null);          // returns -1
            MarshallingSampleNative.CountBytesInString("some string"); // returns 11
        }
Beispiel #2
0
        public static void Run()
        {
            Console.WriteLine("----- Int32 marshalling samples -----");

            // Always start with the same value.
            const int initialValue = 7;
            int       value;

            // Pass Int32 argument by value.
            value = initialValue;
            MarshallingSampleNative.AcceptInt32Argument(value); // returns 7

            // Pass Int32 argument by refernece.
            value = initialValue;
            MarshallingSampleNative.AcceptInt32ByRefArgument(ref value); // returns 7

            // Get Int32 out parameter.
            MarshallingSampleNative.GetInt32OutArgument(out value); // sets value to 9

            // Pass Int32 in-out argument by reference.
            value = initialValue;
            MarshallingSampleNative.ModifyInt32InOutArgument(ref value);

            // Return Int32 value.
            value = MarshallingSampleNative.ReturnInt32Argument(initialValue);
        }
Beispiel #3
0
        public static void Run()
        {
            Console.WriteLine("----- Enum marshalling samples -----");

            // return 2
            int count = MarshallingSampleNative.CountEnumFlags(
                MarshallingSampleNative.EnumFlags.A | MarshallingSampleNative.EnumFlags.C);
        }
        public static void Run()
        {
            Console.WriteLine("----- GUID marshalling samples -----");

            Guid a = new Guid("11111111-2222-3333-4444-556677889900");
            Guid b = new Guid("aaaaaaaa-bbbb-cccc-dddd-eeff77889900");

            MarshallingSampleNative.CompareGuids(a, b); // returns 0
            MarshallingSampleNative.CompareGuids(a, a); // returns 1

            Guid inOutRef = Guid.Empty;
            Guid outRef;
            Guid result = MarshallingSampleNative.CountZeroGuids(a, Guid.Empty, ref b, ref inOutRef, out outRef);
        }
        public static void Run()
        {
            Console.WriteLine("----- Boolean marshalling samples -----");

            const bool initialValue = true;
            bool       value;

            // Pass boolean by value and masrshal it as "Windows" BOOL - which is 32bit int.
            value = initialValue;
            MarshallingSampleNative.AcceptBOOLArgument(value);  // returns 1
            MarshallingSampleNative.AcceptBOOLArgument(false);  // returns 0

            // Pass boolean by reference
            value = initialValue;
            MarshallingSampleNative.AcceptBOOLByRefArgument(ref value);

            // Get boolean out parameter
            MarshallingSampleNative.GetBOOLOutArgument(out value); // sets value to false

            // Pass boolean in-out argument by reference.
            value = initialValue;
            MarshallingSampleNative.ModifyBOOLInOutArgument(ref value); // sets value to false

            // Return boolean value.
            value = MarshallingSampleNative.ReturnBOOLArgument(value);

            // Marshal boolean value in various ways
            int count;

            value = initialValue;
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                count = MarshallingSampleNative.CountTrueValuesWindows(!value, value, !value, value); // returns 2
            }
            else
            {
                count = MarshallingSampleNative.CountTrueValues(!value, value, !value); // returns 1
            }
        }
Beispiel #6
0
        public static void Run()
        {
            Console.WriteLine("----- Numeric marshalling samples -----");

            { // byte
                // Result is 6, both inOutRef and outRef are also set to 6
                byte inRef = 2, inOutRef = 3, outRef;
                byte result = MarshallingSampleNative.SumBytes(1, ref inRef, ref inOutRef, out outRef);
            }

            { // sbyte
                // Result is -6, both inOutRef and outRef are also set to -6
                sbyte inRef = -2, inOutRef = -3, outRef;
                sbyte result = MarshallingSampleNative.SumSBytes(-1, ref inRef, ref inOutRef, out outRef);
            }

            { // ushort
                // Result is 6, both inOutRef and outRef are also set to 6
                ushort inRef = 2, inOutRef = 3, outRef;
                ushort result = MarshallingSampleNative.SumUShorts(1, ref inRef, ref inOutRef, out outRef);
            }

            { // short
                // Result is -6, both inOutRef and outRef are also set to -6
                short inRef = -2, inOutRef = -3, outRef;
                short result = MarshallingSampleNative.SumShorts(-1, ref inRef, ref inOutRef, out outRef);
            }

            { // uint
                // Result is 6, both inOutRef and outRef are also set to 6
                uint inRef = 2, inOutRef = 3, outRef;
                uint result = MarshallingSampleNative.SumUInts(1, ref inRef, ref inOutRef, out outRef);
            }

            { // int
                // Result is -6, both inOutRef and outRef are also set to -6
                int inRef = -2, inOutRef = -3, outRef;
                int result = MarshallingSampleNative.SumInts(-1, ref inRef, ref inOutRef, out outRef);
            }

            { // ulong
                // Result is 6, both inOutRef and outRef are also set to 6
                ulong inRef = 2, inOutRef = 3, outRef;
                ulong result = MarshallingSampleNative.SumULongs(1, ref inRef, ref inOutRef, out outRef);
            }

            { // long
                // Result is -6, both inOutRef and outRef are also set to -6
                long inRef = -2, inOutRef = -3, outRef;
                long result = MarshallingSampleNative.SumLongs(-1, ref inRef, ref inOutRef, out outRef);
            }

            { // float
                // Result is roughly 0.123, both inOutRef and outRef are also set to roughly 0.123
                float inRef = 0.02f, inOutRef = 0.003f, outRef;
                float result = MarshallingSampleNative.SumFloats(0.1f, ref inRef, ref inOutRef, out outRef);
            }

            { // double
                // Result is roughly 0.123, both inOutRef and outRef are also set to roughly 0.123
                double inRef = 0.02f, inOutRef = 0.003f, outRef;
                double result = MarshallingSampleNative.SumDoubles(0.1f, ref inRef, ref inOutRef, out outRef);
            }

            { // decimals
                // Result is 6, both inOutRef and outRef are also set to 6
                decimal inRef = 2, inOutRef = 3, outRef;
                decimal result = MarshallingSampleNative.SumDecimals(1m, ref inRef, ref inOutRef, out outRef);
            }
        }