Esempio n. 1
0
 internal EventTraceLog(long handle, Guid session_guid, string session_name, SafeHGlobalBuffer properties)
 {
     _handle     = handle;
     SessionGuid = session_guid;
     SessionName = session_name;
     _properties = properties.Detach();
     _providers  = new List <EnabledProvider>();
 }
 private SafeBuffer GetInitialBuffer()
 {
     if (Buffer != null)
     {
         return(new SafeHGlobalBuffer(Buffer.DangerousGetHandle(), (int)Buffer.ByteLength, false));
     }
     else if (Bytes != null)
     {
         return(new SafeHGlobalBuffer(Bytes));
     }
     else
     {
         using (var buffer = new SafeHGlobalBuffer(Marshal.SizeOf(Value)))
         {
             Marshal.StructureToPtr(Value, buffer.DangerousGetHandle(), false);
             return(buffer.Detach());
         }
     }
 }
        private static NtResult <SafeHGlobalBuffer> GetDeviceInterfaceProperty(string device_instance, DEVPROPKEY key, out DEVPROPTYPE type, bool throw_on_error)
        {
            int length = 0;
            var result = DeviceNativeMethods.CM_Get_Device_Interface_PropertyW(device_instance, key, out type, SafeHGlobalBuffer.Null, ref length, 0);

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

            using (var buffer = new SafeHGlobalBuffer(length))
            {
                return(DeviceNativeMethods.CM_Get_Device_Interface_PropertyW(device_instance, key, out type, buffer,
                                                                             ref length, 0).ToNtStatus().CreateResult(throw_on_error, () => buffer.Detach()));
            }
        }
        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()));
            }
        }
        private static NtResult <SafeHGlobalBuffer> GetDeviceRegistryPropertyBuffer(Guid class_guid, CmDeviceProperty property, bool throw_on_error)
        {
            int length = 0;
            var result = DeviceNativeMethods.CM_Get_Class_Registry_PropertyW(class_guid, property, out RegistryValueType reg_type,
                                                                             SafeHGlobalBuffer.Null, ref length, 0, IntPtr.Zero);

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

            using (var buffer = new SafeHGlobalBuffer(length))
            {
                return(DeviceNativeMethods.CM_Get_Class_Registry_PropertyW(class_guid, property, out reg_type,
                                                                           buffer, ref length, 0, IntPtr.Zero).ToNtStatus().CreateResult(throw_on_error, () => buffer.Detach()));
            }
        }