NTString() public static method

public static NTString ( char buffer ) : string
buffer char
return string
Esempio n. 1
0
        public static bool TryGetSerialPortName(HDEVINFO deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, out string portName)
        {
            portName = null;

            IntPtr hkey = NativeMethods.SetupDiOpenDevRegKey(deviceInfoSet, ref deviceInfoData);

            if (hkey != (IntPtr)(-1))
            {
                try
                {
                    char[] portNameChars = new char[64]; int portNameLength = 63 * 2;
                    if (0 == NativeMethods.RegQueryValueEx(hkey, "PortName", 0, IntPtr.Zero, portNameChars, ref portNameLength))
                    {
                        Array.Resize(ref portNameChars, portNameLength / 2);

                        string newPortName = NativeMethods.NTString(portNameChars);
                        if (newPortName.Length >= 4 && newPortName.StartsWith("COM"))
                        {
                            portName = newPortName;
                        }
                    }
                }
                finally
                {
                    NativeMethods.RegCloseKey(hkey);
                }
            }

            return(portName != null);
        }
Esempio n. 2
0
 bool TryGetDeviceString(IntPtr handle, Func <IntPtr, char[], int, bool> callback, out string s)
 {
     char[] buffer = new char[128];
     if (!callback(handle, buffer, Marshal.SystemDefaultCharSize * buffer.Length))
     {
         s = null;
         return(Marshal.GetLastWin32Error() == NativeMethods.ERROR_GEN_FAILURE);
     }
     s = NativeMethods.NTString(buffer); return(true);
 }
Esempio n. 3
0
        public static bool TryGetDeviceRegistryProperty(HDEVINFO deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, uint property, out string value)
        {
            value = null;

            uint propertyDataType; char[] propertyValueChars = new char[64]; int propertyValueLength = 63 * 2;

            if (SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref deviceInfoData, property, out propertyDataType,
                                                 propertyValueChars, propertyValueLength, IntPtr.Zero))
            {
                if (propertyDataType == REG_SZ)
                {
                    value = NativeMethods.NTString(propertyValueChars);
                }
            }

            return(value != null);
        }
Esempio n. 4
0
        public override string GetIndexedString(int stringIndex)
        {
            string indexedString = null;

            if (!TryOpenToGetInfo(handle =>
            {
                char[] buffer = new char[128];
                if (!NativeMethods.HidD_GetIndexedString(handle, stringIndex, buffer, Marshal.SystemDefaultCharSize * buffer.Length))
                {
                    return(Marshal.GetLastWin32Error() == NativeMethods.ERROR_GEN_FAILURE);
                }
                indexedString = NativeMethods.NTString(buffer);
                return(true);
            }))
            {
                throw DeviceException.CreateIOException(this, "Failed to get info.");
            }
            return(indexedString);
        }
Esempio n. 5
0
        internal void GetInfoComplete(IntPtr handle)
        {
            try {
                char[] buffer = new char[128];

                _manufacturer = NativeMethods.HidD_GetManufacturerString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : "";
                _productName  = NativeMethods.HidD_GetProductString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : "";
                _serialNumber = NativeMethods.HidD_GetSerialNumberString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : "";

                IntPtr preparsed;
                if (NativeMethods.HidD_GetPreparsedData(handle, out preparsed))
                {
                    NativeMethods.HIDP_CAPS caps;
                    int statusCaps = NativeMethods.HidP_GetCaps(preparsed, out caps);
                    if (statusCaps == NativeMethods.HIDP_STATUS_SUCCESS)
                    {
                        _maxInput   = caps.InputReportByteLength;
                        _maxOutput  = caps.OutputReportByteLength;
                        _maxFeature = caps.FeatureReportByteLength;
                    }
                    NativeMethods.HidD_FreePreparsedData(preparsed);
                }
            } finally {
                NativeMethods.CloseHandle(handle);
            }

            lock (_completeSync) {
                _complete = true;
                Monitor.PulseAll(_completeSync);
            }
        }