コード例 #1
0
        public static short MTBDataToArray(ShortStruct list)
        {
            int   size        = Marshal.SizeOf(typeof(short));
            short resultValue = (short)Marshal.PtrToStructure(new IntPtr(list.value.ToInt64()), typeof(short));

            Marshal.FreeCoTaskMem(list.value);

            return(resultValue);
        }
コード例 #2
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);
        }
コード例 #3
0
 public static void InitializeShortData(ref ShortStruct shortStruct)
 {
     //short number = -1;
     shortStruct.value = Marshal.AllocCoTaskMem(ShortSize);
     //Marshal.StructureToPtr(number, shortStruct.value, false);
 }
コード例 #4
0
 public static extern bool GetUSBDeviceProperties(int Number, ShortStruct pPoductId, MTB_DATA pName, MTB_DATA pSerialNumber);