Esempio n. 1
0
        static void Main(string[] args)
        {
            var p1Size = new SvgUnit(SvgUnitType.Millimeter, 181);
            var doc    = new SvgDocument
            {
                Width  = p1Size,
                Height = p1Size
            };

            var spacer = new Spacer(boltDiameter, "Spacer");

            spacer.Create();
            spacer.Transforms.Add(new SvgTranslate(p1Size / 3, p1Size / 3));
            doc.Children.Add(spacer);


            var bigTurret = TurretMount.JumboAndStandard(boltDiameter);

            bigTurret.Create();
            bigTurret.Transforms.Add(new SvgTranslate(p1Size * 2 / 3, p1Size * 2 / 3));
            doc.Children.Add(bigTurret);

            var protractor = new Protractor(boltDiameter, 20, 12, 10);

            protractor.Create();
            protractor.Transforms.Add(new SvgTranslate(p1Size, 0));
            doc.Children.Add(protractor);

            var pointer = new Pointer(boltDiameter, new float[] { 83, 112, 231, 170 });

            pointer.Create();
            doc.Children.Add(pointer);

            File.WriteAllText(@"c:\temp\Drawing.svg", doc.GetXML());
        }
Esempio n. 2
0
        public void TestGetByte()
        {
            var Data = Pointer <byte> .Create(new AllocatedMemory(new byte[] { 1, 2, 3 }));

            Assert.AreEqual(1, bytestream.get_byte(ref Data));
            Assert.AreEqual(2, bytestream.get_byte(ref Data));
            Assert.AreEqual(3, bytestream.get_byte(ref Data));
        }
Esempio n. 3
0
        public static void Can_call_ansi_extern_function_with_null_context_and_group()
        {
            int    error;
            int    readersLength = 16;
            LPMSTR readersBuffer = default;

            try
            {
                do
                {
                    readersBuffer = Pointer.Create <LPMSTR>(
                        Marshal.ReAllocCoTaskMem(readersBuffer.Pointer, 1 * readersLength)
                        );
                    error = SCardListReadersA(default, null, readersBuffer,
        public static void Can_call_ansi_extern_function_with_null_context()
        {
            int    error;
            int    groupLength = 16;
            LPMSTR groupBuffer = default;

            try
            {
                do
                {
                    groupBuffer = Pointer.Create <LPMSTR>(
                        Marshal.ReAllocCoTaskMem(groupBuffer.Pointer, 1 * groupLength)
                        );
                    error = SCardListReaderGroupsA(default, groupBuffer,
Esempio n. 5
0
        public static void Can_list_all_cards_with_null_context_ansi()
        {
            int    error;
            int    cardsLength = 16;
            LPMSTR cardsBuffer = default;

            try
            {
                do
                {
                    cardsBuffer = Pointer.Create <LPMSTR>(
                        Marshal.ReAllocCoTaskMem(cardsBuffer.Pointer,
                                                 1 * cardsLength)
                        );
                    error = SCardListCardsA(default, default, default,
Esempio n. 6
0
        public static void Can_call_lptstr_extern_function()
        {
            var buffer = Pointer.Create <LPTSTR>(Marshal.AllocCoTaskMem(Marshal.SystemDefaultCharSize * MAX_PATH));

            try
            {
                var length = GetSystemDirectory(buffer, MAX_PATH);
                if (length == 0)
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
                }
                var path = AutoStringPointer.MarshalToString(buffer, length);
                Assert.NotNull(path);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer.Pointer);
            }
        }
Esempio n. 7
0
        public static void Can_call_lpwstr_extern_function()
        {
            var buffer = Pointer.Create <LPWSTR>(Marshal.AllocCoTaskMem(2 * MAX_PATH));

            try
            {
                var length = GetWindowsDirectoryW(buffer, MAX_PATH);
                if (length == 0)
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
                }
                var path = UnicodeStringPointer.MarshalToString(buffer, length);
                Assert.NotNull(path);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer.Pointer);
            }
        }
Esempio n. 8
0
        public static void Can_call_lptstr_extern_function(COMPUTER_NAME_FORMAT nameType)
        {
            int length = 255;
            var buffer = Pointer.Create <LPTSTR>(Marshal.AllocCoTaskMem(Marshal.SystemDefaultCharSize * length));

            try
            {
                bool successful = GetComputerNameEx(nameType, buffer, ref length);
                if (!successful)
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
                }
                var path = AutoStringPointer.MarshalToString(buffer, length);
                Assert.NotNull(path);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer.Pointer);
            }
        }
Esempio n. 9
0
        public static void Unknown_length_LPCMTSTR_foreach_yields_correct_strings()
        {
            var(array, str) = GetTestMultiString();
            var ptr = Marshal.StringToCoTaskMemAuto(str);

            try
            {
                var multiStrPtr = Pointer.Create <LPCMTSTR>(ptr);

                int iteration = 0;
                foreach (var(strPtr, length) in multiStrPtr.AsEnumerable())
                {
                    Assert.Equal(array[iteration], strPtr.MarshalToString(length));
                    iteration++;
                }
                Assert.Equal(array.Length, iteration);
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }
Esempio n. 10
0
        private object Decode <TType>(byte[] Data, AVCodec AVCodec, Action <AVCodecContext, AVPacket, TType> Action)
        {
            var context = new AVCodecContext();
            var packet  = new AVPacket();

            packet.data = Pointer <byte> .Create(new AllocatedMemory(Data));

            packet.size = Data.Length;

            context.get_buffer = (AVCodecContext, AVFrame) =>
            {
                var width  = AVCodecContext.width;
                var height = AVCodecContext.height;
                AVFrame.linesize[0] = width * 4;
                AVFrame.data[0]     = CLib.malloc(AVFrame.linesize[0] * height);
                return(0);
            };

            context.release_buffer = (AVCodecContext, AVFrame) =>
            {
                CLib.free(AVFrame.data[0]);
            };

            AVCodec.init(context);
            try
            {
                object obj = null;
                if (AVCodec.decode(context, ref obj, packet) < 0)
                {
                    throw(new Exception());
                }
                Action(context, packet, (TType)obj);
                return(obj);
            }
            finally
            {
                AVCodec.close(context);
            }
        }
Esempio n. 11
0
        public static void Empty_known_length_LPMWSTR_zero_foreach_iterations()
        {
            var ptr = Marshal.StringToCoTaskMemUni(emptyMultiString);

            try
            {
                var multiStrPtr = Pointer.Create <LPMWSTR>(ptr);

                int iterations = 0;
                foreach (var(strPtr, strLen) in multiStrPtr.AsEnumerable(emptyMultiString.Length))
                {
                    _ = strPtr;
                    _ = strLen;
                    iterations++;
                }

                Assert.Equal(0, iterations);
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }