Exemplo n.º 1
0
        public static void InitialMTBDATA(ref MTB_DATA list)
        {
            list.count = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)));
            Marshal.StructureToPtr(-1, list.count, false);
            Console.WriteLine("MTBServer : count is set to: {0} ", (int)Marshal.PtrToStructure(new IntPtr(list.count.ToInt32()), typeof(int)));

            list.buff = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(char)) * 1024);
        }
Exemplo n.º 2
0
        public static void InitializeMtbData(ref MTB_DATA list)
        {
            int charNumber = 100;

            list.count = Marshal.AllocCoTaskMem(IntSize);
            Marshal.StructureToPtr(charNumber, list.count, false);

            list.buff = Marshal.AllocCoTaskMem(CharSize * charNumber);
        }
Exemplo n.º 3
0
        public static byte[] MTBDataToArray(MTB_DATA list)
        {
            int size  = Marshal.SizeOf(typeof(char));
            int count = (int)Marshal.PtrToStructure(new IntPtr(list.count.ToInt64()), typeof(int));

            if (count == -1)
            {
                return(null);
            }

            byte[] byteArray = new byte[count];
            for (int i = 0; i < count; i++)
            {
                byteArray[i] = (byte)Marshal.PtrToStructure(new IntPtr(list.buff.ToInt64() + i * size), typeof(byte));
            }

            Marshal.FreeCoTaskMem(list.buff);

            return(byteArray);
        }
Exemplo n.º 4
0
        public static bool GetUSBDevicePropertiesByPInvoke(int Number, out short pPoductId, out string pName, out string pSerialNumber)
        {
            ShortStruct poductId = new ShortStruct();

            InitializeShortData(ref poductId);

            MTB_DATA name = new MTB_DATA();

            InitializeMtbData(ref name);

            MTB_DATA serialNumber = new MTB_DATA();

            InitializeMtbData(ref serialNumber);

            bool result = GetUSBDeviceProperties(Number, poductId, name, serialNumber);

            pPoductId = MTBDataToArray(poductId);
            byte[] pPoductIdByte = MTBDataToArray(name);
            pName = ByteArrayToStringConverter1(pPoductIdByte);
            byte[] pSerialNumberByte = MTBDataToArray(serialNumber);
            pSerialNumber = ByteArrayToStringConverter1(pSerialNumberByte);

            return(result);
        }
Exemplo n.º 5
0
 public static extern bool GetUSBDeviceProperties(int Number, ShortStruct pPoductId, MTB_DATA pName, MTB_DATA pSerialNumber);