コード例 #1
0
        private string GetPropertString(UInt32 deviceInstance, ConfigManagerAPI.DeviceInfo devPropInfo)
        {
            string property = "";

            UInt32 propertyType = 0;
            IntPtr buf          = new IntPtr();
            UInt32 bufSize      = 0;

            uint result = ConfigManagerAPI.CM_Get_DevNode_PropertyW(deviceInstance, ref devPropInfo, ref propertyType, buf, ref bufSize, 0);

            if (result == SMALL_BAFFER && propertyType == STRING_TYPE)
            {
                buf = Marshal.AllocHGlobal((int)bufSize * 2);

                result = ConfigManagerAPI.CM_Get_DevNode_PropertyW(deviceInstance, ref devPropInfo, ref propertyType, buf, ref bufSize, 0);

                if (result == 0)
                {
                    property = ReadNullTerminatedStringFromBuffer(buf, bufSize);
                }

                Marshal.FreeHGlobal(buf);
            }

            return(property);
        }
コード例 #2
0
        private List <string> GetPropertStringList(UInt32 deviceInstance, ConfigManagerAPI.DeviceInfo devPropInfo)
        {
            List <string> property = new List <string>();

            UInt32 propertyType = 0;
            IntPtr buf          = new IntPtr();
            UInt32 bufSize      = 0;

            uint result = ConfigManagerAPI.CM_Get_DevNode_PropertyW(deviceInstance, ref devPropInfo, ref propertyType, buf, ref bufSize, 0);

            if (result == SMALL_BAFFER && propertyType == (STRING_TYPE + LIST_TYPE))
            {
                buf = Marshal.AllocHGlobal((int)bufSize * 2);

                result = ConfigManagerAPI.CM_Get_DevNode_PropertyW(deviceInstance, ref devPropInfo, ref propertyType, buf, ref bufSize, 0);

                if (result == 0)
                {
                    IntPtr pointer = buf;
                    while (bufSize > 0)
                    {
                        string element = ReadNullTerminatedStringFromBuffer(pointer, bufSize);
                        if (String.IsNullOrEmpty(element))
                        {
                            break;
                        }
                        int offset = element.Length + 1;
                        offset *= 2;
                        property.Add(element);
                        pointer = IntPtr.Add(pointer, offset);
                    }
                }

                Marshal.FreeHGlobal(buf);
            }

            return(property);
        }