Ejemplo n.º 1
0
        public static string GetStringPropertyForDevice(IntPtr info, Native.SP_DEVINFO_DATA devdata, DisableHardware.DEVPROPKEY key)
        {
            uint   proptype, outsize;
            IntPtr buffer = IntPtr.Zero;

            try
            {
                uint buflen = 512;
                buffer = Marshal.AllocHGlobal((int)buflen);
                Native.SetupDiGetDevicePropertyW(
                    info,
                    ref devdata,
                    ref key,
                    out proptype,
                    buffer,
                    buflen,
                    out outsize,
                    0);
                byte[] lbuffer = new byte[outsize];
                Marshal.Copy(buffer, lbuffer, 0, (int)outsize);

                return(Encoding.Unicode.GetString(lbuffer));
            }
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buffer);
                }
            }
        }