From bce8be2b0a016a492b755dd422a1e3808636d5b3 Mon Sep 17 00:00:00 2001 From: Brent Beardsley Date: Wed, 26 Oct 2011 17:24:15 -0600 Subject: [PATCH] get/expose ProductString - will be Buzz for wired and Wbuzz for wireless --- AssemblyInfo.cs | 2 +- HIDDevice.cs | 9 +++++++++ IBuzzHandsetDevice.cs | 2 +- Win32USB.cs | 11 ++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index e38febf..5953786 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -26,7 +26,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.1.1")] +[assembly: AssemblyVersion("1.0.1.2")] // // In order to sign your assembly you must specify a key to use. Refer to the diff --git a/HIDDevice.cs b/HIDDevice.cs index 876d0ed..4130703 100644 --- a/HIDDevice.cs +++ b/HIDDevice.cs @@ -27,6 +27,11 @@ public abstract class HIDDevice : Win32Usb, IDisposable /// public int InputReportLength { get; private set; } + /// + /// Product name + /// + public string ProductString { get; private set; } + #endregion Properties #region IDisposable Members @@ -74,6 +79,10 @@ private void Initialise(string strPath) { try { + var buffer = Marshal.AllocHGlobal(126);//max alloc for string; + ProductString = HidD_GetProductString(_handle, buffer, 126) ? Marshal.PtrToStringAuto(buffer) : string.Empty; + Marshal.FreeHGlobal(buffer); + HidCaps oCaps; HidP_GetCaps(lpData, out oCaps); // extract the device capabilities from the internal buffer InputReportLength = oCaps.InputReportByteLength; // get the input... diff --git a/IBuzzHandsetDevice.cs b/IBuzzHandsetDevice.cs index f1ac153..66bfda8 100644 --- a/IBuzzHandsetDevice.cs +++ b/IBuzzHandsetDevice.cs @@ -23,6 +23,6 @@ public interface IBuzzHandsetDevice /// event EventHandler DeviceRemoved; - + string ProductString { get; } } } \ No newline at end of file diff --git a/Win32USB.cs b/Win32USB.cs index bc390ae..9e065ca 100644 --- a/Win32USB.cs +++ b/Win32USB.cs @@ -216,6 +216,7 @@ public class DeviceBroadcastInterface /// True if successful [DllImport("hid.dll", SetLastError = true)] protected static extern int HidP_GetCaps(IntPtr lpData, out HidCaps oCaps); + /// /// Creates/opens a file, serial port, USB device... etc /// @@ -229,6 +230,7 @@ public class DeviceBroadcastInterface /// [DllImport("kernel32.dll", SetLastError = true)] protected static extern IntPtr CreateFile([MarshalAs(UnmanagedType.LPStr)] string strName, uint nAccess, uint nShareMode, IntPtr lpSecurity, uint nCreationFlags, uint nAttributes, IntPtr lpTemplate); + /// /// Closes a window handle. File handles, event handles, mutex handles... etc /// @@ -236,7 +238,14 @@ public class DeviceBroadcastInterface /// True if successful. [DllImport("kernel32.dll", SetLastError = true)] protected static extern int CloseHandle(IntPtr hFile); - #endregion + + [DllImport("hid.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)] + internal static extern bool HidD_GetProductString( + IntPtr hDevice, + IntPtr buffer, + uint bufferLength); + + #endregion P/Invoke #region Public methods ///