예제 #1
0
        private static NtResult <SafeHGlobalBuffer> GetClassProperty(Guid class_guid, CmClassType flags, DEVPROPKEY key, out DEVPROPTYPE type, bool throw_on_error)
        {
            int length = 0;
            var result = DeviceNativeMethods.CM_Get_Class_PropertyW(class_guid, key, out type, SafeHGlobalBuffer.Null, ref length, flags);

            if (result != CrError.BUFFER_SMALL)
            {
                return(result.ToNtStatus().CreateResultFromError <SafeHGlobalBuffer>(throw_on_error));
            }

            using (var buffer = new SafeHGlobalBuffer(length)) {
                return(DeviceNativeMethods.CM_Get_Class_PropertyW(class_guid, key, out type, buffer,
                                                                  ref length, flags).ToNtStatus().CreateResult(throw_on_error, () => buffer.Detach()));
            }
        }
        internal static NtResult <Guid> GetClassStringList(Guid class_guid, bool interface_guid, DEVPROPKEY key, bool throw_on_error)
        {
            int length = 16;
            var result = DeviceNativeMethods.CM_Get_Class_PropertyW(class_guid, key, out DEVPROPTYPE type, out Guid value, ref length,
                                                                    interface_guid ? CmClassType.Interface : CmClassType.Installer).ToNtStatus();

            if (!result.IsSuccess())
            {
                return(result.CreateResultFromError <Guid>(throw_on_error));
            }
            if (type != DEVPROPTYPE.GUID)
            {
                return(NtStatus.STATUS_BAD_KEY.CreateResultFromError <Guid>(throw_on_error));
            }
            return(value.CreateResult());
        }