Problem with SetupDiGetDriverInfoDetail API

Locked Problem with SetupDiGetDriverInfoDetail API

  • lundi 12 mars 2012 21:30
     
      A du code

    Hi Guys,

    I'm having trouble with an API call to SetupDiGetDriverInfoDetail.  It creates a PInvoke stack imbalance.  I'm sure I messed up something in the import or the structure but I can't see it.

    Here's the code:

    Friend Sub New(ByVal ptrInfoSet As IntPtr, ByVal diiIstanceInfo As DeviceInstanceInfo, ByVal ddiDriverInfo As DeviceDriverInfo)
    		Dim ptrQueue As IntPtr = NativeMethods.SetupOpenFileQueue()
    		Dim dipInstallParameters As New DeviceInstallParameters()
    		Dim didDriverInfoDetailData As New DeviceDriverInfoDetailData
    		Dim ddfFileCallBack As DeviceDriverFileCallBack = AddressOf OnDriverFile
    		Dim intResult As Integer
    		strManufacturer = ddiDriverInfo.Manufacturer
    		strProvider = ddiDriverInfo.Provider
    		strDescription = ddiDriverInfo.Description
    		dteReleaseDate = DateTime.FromFileTime(ddiDriverInfo.ReleaseDate)
    		verVersion = New Version(CInt(((ddiDriverInfo.Version >> 48) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 32) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 16) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 0) And &HFFFF)))
    		lstFiles = New List(Of String)()
    		If ptrQueue <> New IntPtr(-1) Then
    			dipInstallParameters.Size = Marshal.SizeOf(GetType(DeviceInstallParameters))
    			If NativeMethods.SetupDiGetDeviceInstallParamsW(ptrInfoSet, diiIstanceInfo, dipInstallParameters) Then
    				dipInstallParameters.Flags = dipInstallParameters.Flags Or DeviceInstallFlags.NOVCP
    				dipInstallParameters.hFileQueue = ptrQueue
    				If NativeMethods.SetupDiSetDeviceInstallParamsW(ptrInfoSet, diiIstanceInfo, dipInstallParameters) Then
    					If NativeMethods.SetupDiSetSelectedDriverW(ptrInfoSet, diiIstanceInfo, ddiDriverInfo) Then
    						If NativeMethods.SetupDiCallClassInstaller(DeviceDriverInstallFunction.InstallDeviceFiles, ptrInfoSet, diiIstanceInfo) Then
    							NativeMethods.SetupScanFileQueueW(ptrQueue, DeviceDriverFileQueueFlags.UseCallback, IntPtr.Zero, ddfFileCallBack, IntPtr.Zero, intResult)
    							GC.KeepAlive(ddfFileCallBack)
    						End If
    					End If
    				End If
    			End If
    			NativeMethods.SetupCloseFileQueue(ptrQueue)
    		End If
    		didDriverInfoDetailData.Size = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData))
    		If NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, ddiDriverInfo, ddiDriverInfo, didDriverInfoDetailData, didDriverInfoDetailData.Size, didDriverInfoDetailData.Size) Then
    			MsgBox(didDriverInfoDetailData.InfFileName)
    		End If
    	End Sub
    It fails on the call to setupdigetdriverinfodetail.

    Here's the import:

    	<DllImport("setupapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
    	<ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)> _
    	Public Function SetupDiGetDriverInfoDetail(<[In]()> ByVal hDeviceInfoSet As IntPtr, <[In]()> ByVal DeviceInfoData As DeviceDriverInfo, <[In]()> ByVal DriverInfoData As DeviceDriverInfo, <Out()> ByRef DriverInfoDetailData As DeviceDriverInfoDetailData, <[In]()> ByVal DriverInfoDetailDataSize As Int32, <Out()> ByRef RequiredSize As Int32) As Boolean
    	End Function

    Here's my structures:

    Public Structure DeviceDriverInfo
    	Public Size As Integer
    	<MarshalAs(UnmanagedType.U4)> _
    	Public DriverType As DeviceDriverType
    	Public Reserved As IntPtr
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public Description As String
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public Manufacturer As String
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public Provider As String
    	Public ReleaseDate As Long
    	Public Version As Long
    End Structure
    <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
    Public Structure DeviceDriverInfoDetailData
    	Public Size As Int32
    	Public InfDate As System.Runtime.InteropServices.ComTypes.FILETIME
    	Public CompatIDsOffset As Int32
    	Public CompatIDsLength As Int32
    	Public Reserved As IntPtr
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public SectionName As [String]
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
     Public InfFileName As [String]
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public DrvDescription As [String]
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
     Public HardwareID As [String]
    End Structure

    I'm sure I just got things crossed up somewhere, but I've been staring at it for the last hour and can't see straight.  Need a fresh set of eyes.

    Thanks

Toutes les réponses

  • mardi 13 mars 2012 03:09
     
     
    Call SetupDiGetDriverInfoDetail to get the RequiredSize of the DriverInfoDetailData structure.  Does the size match the size you supply?
  • mardi 13 mars 2012 03:52
     
      A du code

    Here's my code:

    		didDriverInfoDetailData.Size = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData))
    		If NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, diiIstanceInfo, diiIstanceInfo, diiIstanceInfo, didDriverInfoDetailData.Size, didDriverInfoDetailData.Size) Then
    			MsgBox(didDriverInfoDetailData.InfFileName)
    		End If

    No message box is displayed so the call fails with an error. Haven't checked the error code.  I think there's still something wrong with my structure
  • mardi 13 mars 2012 04:28
     
     
    Change your code to determine the RequiredSize of the structure.  If you want to add a message box, that's fine, but you can check it with intellisense also.  You need to study the documentation to learn how to use the method.  You make a call to determine the required size, allocate the structure and make a second call.
  • mardi 13 mars 2012 18:18
     
     

    I'm not sure I understand what you're saying..  I thought didDriverInfoDetailData.Size = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData)) sets the size of the structure.  I have studied what documentation I am able to find which isn't much.  I haven't been able to locate any sample code when demonstrates calling the API only documentation showing the proper structure of the typedef and function parameters.  If you can direct me to a sample code stub which shows how to properly call the function I would appreciate it.

  • mardi 13 mars 2012 18:44
     
     
    You should be able to find complete documentation using the help menu of your IDE.  Paste "SetupDiGetDriverInfoDetail" in the search box of the Index pane.  If you're using VS2008 or earlier and you haven't downloaded the MSDN library, you'll have to use the online help.  There is no reason for doing anything else until you get a valid value for the required size of the structure.  Working with the setupapi is complex.  You really should have some idea of what you are doing to use it.
  • mardi 13 mars 2012 18:51
    Modérateur
     
     

    Issues with unmanaged API calls would probably be better addressed in the Interop and Upgrade forum.  I'll move this thread there since you suspect the issue is with the COM Interop portion of your code.

    One thing I do notice is the use of Int32 instead of IntPtr - could be causing an issue if you are compiling on a 64bit machine with Any-CPU or 64Bit profiles....


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • mardi 13 mars 2012 19:04
     
     
    I do have experience using Win32 API. Just never used this one before.  I am VERY aware that it's complex and even tricky sometimes.  Thanks for being so sarcastic I appreciate it.
  • mardi 13 mars 2012 19:10
     
     
    Thanks Reed for the help and for not being sarcastic in your reply.  I understand what you're saying about where it really should be posted. I've posted other similar stuff there and got no replies at all.  I do understand how to use API, I'm just struggling with the differences in .Net, it's confusing and I haven't been able to find a reference which covers Win32 API in the .Net world.  I have a reference by Dan Appleman but it's not much help.
  • mardi 13 mars 2012 20:49
     
     

    I do have experience using Win32 API. Just never used this one before.  I am VERY aware that it's complex and even tricky sometimes.  Thanks for being so sarcastic I appreciate it.

    The note in the documentation states: 
    Note  DriverInfoDetailData.cbSize must not be set to the value of the DriverInfoDetailDataSize parameter
  • mercredi 14 mars 2012 04:14
     
      A du code

    Hi Guys,

    I'm still struggling with this API call.  I did find a similar API and I've tried to use it as a guide for what I need to do here.  I think I'm close, but I can't quite get it.  Hope someone can help me out here.  Here's my code:

    	Friend Sub New(ByVal ptrInfoSet As IntPtr, ByVal diiIstanceInfo As DeviceInstanceInfo, ByVal ddiDriverInfo As DeviceDriverInfo)
    		Dim ptrQueue As IntPtr = NativeMethods.SetupOpenFileQueue()
    		Dim dipInstallParameters As New DeviceInstallParameters()
    		Dim didDummy As DeviceDriverInfoDetailData = Nothing
    		Dim didDriverInfoDetailData As New DeviceDriverInfoDetailData
    		Dim ddfFileCallBack As DeviceDriverFileCallBack = AddressOf OnDriverFile
    		Dim intResult As Integer
    		Dim intReturnLength As Integer
    		Dim blnResult As Boolean = NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, diiIstanceInfo, diiIstanceInfo, didDummy, didDummy.Size, intReturnLength)
    		Dim intError As Integer
    		Dim intBaseSize As Integer = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData))
    		Dim intNumberOfElements As Integer = intReturnLength \ intBaseSize
    		Dim intAllocatedSize As Integer = (intNumberOfElements * intBaseSize)
    		strManufacturer = ddiDriverInfo.Manufacturer
    		strProvider = ddiDriverInfo.Provider
    		strDescription = ddiDriverInfo.Description
    		strDriverPath = dipInstallParameters.DriverPath
    		dteReleaseDate = DateTime.FromFileTime(ddiDriverInfo.ReleaseDate)
    		verVersion = New Version(CInt(((ddiDriverInfo.Version >> 48) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 32) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 16) And &HFFFF)), CInt(((ddiDriverInfo.Version >> 0) And &HFFFF)))
    		lstFiles = New List(Of String)()
    		If ptrQueue <> New IntPtr(-1) Then
    			dipInstallParameters.Size = Marshal.SizeOf(GetType(DeviceInstallParameters))
    			If NativeMethods.SetupDiGetDeviceInstallParamsW(ptrInfoSet, diiIstanceInfo, dipInstallParameters) Then
    				dipInstallParameters.Flags = dipInstallParameters.Flags Or DeviceInstallFlags.NOVCP
    				dipInstallParameters.hFileQueue = ptrQueue
    				If NativeMethods.SetupDiSetDeviceInstallParamsW(ptrInfoSet, diiIstanceInfo, dipInstallParameters) Then
    					If NativeMethods.SetupDiSetSelectedDriverW(ptrInfoSet, diiIstanceInfo, ddiDriverInfo) Then
    						If NativeMethods.SetupDiCallClassInstaller(DeviceDriverInstallFunction.InstallDeviceFiles, ptrInfoSet, diiIstanceInfo) Then
    							NativeMethods.SetupScanFileQueueW(ptrQueue, DeviceDriverFileQueueFlags.UseCallback, IntPtr.Zero, ddfFileCallBack, IntPtr.Zero, intResult)
    							GC.KeepAlive(ddfFileCallBack)
    						End If
    					End If
    				End If
    			End If
    			NativeMethods.SetupCloseFileQueue(ptrQueue)
    		End If
    		'intBaseSize = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData))
    		'If NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, diiIstanceInfo, diiIstanceInfo, didDummy, didDummy.Size, intReturnLength) Then
    		'Throw Fail("SetupDiGetDriverInfoDetail Failed.")
    		'End If
    		'blnResult = NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, diiIstanceInfo, diiIstanceInfo, didDummy, didDummy.Size, intReturnLength)
    		'intNumberOfElements = intReturnLength \ intBaseSize
    		'intAllocatedSize = (intNumberOfElements * intBaseSize)
    		If blnResult Then
    			Throw Fail("SetupDiGetDriverInfoDetail Failed.")
    		End If
    		'intError = Marshal.GetLastWin32Error()
    		If Marshal.GetLastWin32Error() <> ERROR_INSUFFICIENT_BUFFER Then
    			Throw Fail("Insufficient Space In The Buffer.", Marshal.GetLastWin32Error().ToString())
    		End If
    		intBaseSize = Marshal.SizeOf(GetType(DeviceDriverInfoDetailData))
    		intNumberOfElements = intReturnLength \ intBaseSize
    		intAllocatedSize = (intNumberOfElements * intBaseSize)
    		If Not NativeMethods.SetupDiGetDriverInfoDetail(ptrInfoSet, diiIstanceInfo, diiIstanceInfo, didDriverInfoDetailData, intBaseSize, intAllocatedSize) Then
    			Throw Fail("SetupDiGetDriverInfoDetail Failed", Marshal.GetLastWin32Error().ToString())
    		Else
    			strINFName = didDriverInfoDetailData.InfFileName
    			strSectionName = didDriverInfoDetailData.SectionName
    			dteINFDate = DateTime.FromFileTime(didDriverInfoDetailData.InfDate.dwHighDateTime)
    		End If
    	End Sub


    Here's my Import:

    <DllImport("setupapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
    	<ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)> _
    	Public Function SetupDiGetDriverInfoDetail(<[In]()> ByVal hDeviceInfoSet As IntPtr, <[In]()> ByRef DeviceInfoData As DeviceInstanceInfo, <[In]()> ByRef DriverInfoData As DeviceInstanceInfo, <[In](), Out()> ByRef DriverInfoDetailDatail As DeviceDriverInfoDetailData, ByVal DriverInfoDetailDataSize As Int32, ByRef RequiredSize As Int32) As Boolean
    	End Function

    Here's my structure:

    <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
    Public Structure DeviceDriverInfoDetailData
    	Public Size As Int32
    	Public InfDate As System.Runtime.InteropServices.ComTypes.FILETIME
    	Public CompatIDsOffset As Int32
    	Public CompatIDsLength As Int32
    	Public Reserved As IntPtr
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public SectionName As String
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
    	Public InfFileName As String
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    	Public DrvDescription As String
    	<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
    	Public HardwareID As String
    End Structure

    <StructLayout(LayoutKind.Sequential, Pack:=4)> _
    Public Structure DeviceInstanceInfo
    	Public Size As Integer
    	Public ClassGuid As Guid
    	Public InstanceID As Integer
    	Public Reserved As IntPtr
    End Structure

    I understand how the function call is supposed to work.  It has to be called twice.  The first call should return the required size of the buffer needed to hold the information.  That value is used in the second call to actually return the data.  All my attempts so far do not return the required size.  It always comes back 0
  • vendredi 16 mars 2012 03:18
     
     

    Ok, let's continue here as declared in your other thread.

    My current task is handling the hardware IDs, which is the last member of DeviceDriverInfoDetailData. (Yes, I can handle it.) Though, reading the documentation of SetupDiGetDriverInfoDetail there are some things to consider. The whole structure must be marshalled in two steps because of the dynamic length. I managed to copy the hardware IDs to a String. It's also not a problem to split the string, but the CompatIDsOffset must also be taken into account, so I want to handle it directly when working with the marshaller, not later because the character set has to be considered also.

    Anyway, just wanted to say I'm still at it (close to finish), but it's 4:19 AM here now, so I'll continue tomorrow.


    Armin

  • vendredi 16 mars 2012 03:26
     
     
    Wow nice to know I'm not the only one who stays up til insane hours.   I'm just working on the output of device/device driver properties.  Still trying to figure some of them out but I am making progress.  Get some sleep my friend, I'm not far behind you.  I think I've had enough fun for one day and I'm pretty happy with the progress I've made.  Good night
  • vendredi 16 mars 2012 04:09
     
      A du code

    Output works:

    #76
        Description = Windows RAM-Laufwerkcontroller
        DriverDate = 21.06.2006 02:00:00
        DriverType = ClassDriver
        DriverVersion = 1688854653321217
        ManufacturerName = Microsoft
        ProviderName = Microsoft
        Details:
            DriverDescription = Windows RAM-Laufwerkcontroller
            InfDate = 13.07.2009 22:39:18
            InfFileName = C:\Windows\INF\ramdisk.inf
            SectionName = BusInstall
            HardwareID = ramdisk
            CompatibleIDs:
                detectedinternal\ramdisk
                detected\ramdisk
    

    I'll have to put everything together tomorrow.

    Good night - the last time for today. ;)


    Armin

  • vendredi 16 mars 2012 11:14
     
     Traitée A du code

    New day... :)

    As I said in the other thread, I'm using a managed wrapper for all this, so I can't post the code creating the output. However here's the unmanaged helper function for calling SetupDiGetDriverInfoDetail and "post processing":

       Public Shared Function GetDriverInfoDetail( _
          ByVal DeviceInfoSet As IntPtr, _
          ByVal DriverInfoData As SP_DRVINFO_DATA) _
          As ExtendedDriverInfoDetail
    
          Dim RequiredSize As UInt32
    
          Functions.SetupDiGetDriverInfoDetail(DeviceInfoSet, IntPtr.Zero, DriverInfoData, IntPtr.Zero, 0, RequiredSize) 'always returns False
    
          If Win32.Helper.GetLastWin32Error = Win32.Errors.InsufficientBuffer Then
             Dim ptr = Marshal.AllocHGlobal(CInt(RequiredSize))
    
             Try
                Dim type = GetType(SP_DRVINFO_DETAIL_DATA)
    
                Marshal.WriteInt32(ptr, Marshal.SizeOf(type))
    
                If Functions.SetupDiGetDriverInfoDetail(DeviceInfoSet, IntPtr.Zero, DriverInfoData, ptr, RequiredSize, IntPtr.Zero) Then
                   Dim result As SP_DRVINFO_DETAIL_DATA
                   Dim OffsetHardwareID = Marshal.OffsetOf(type, "HardwareID")
                   Dim ptrHardwareID As IntPtr = ptr.Add(OffsetHardwareID)
                   Dim HardwareIDLength = CInt(RequiredSize) - OffsetHardwareID.ToInt32
                   Dim HardwareID As String = Nothing
                   Dim CompatibleIDsList As List(Of String) = Nothing
    
                   result = DirectCast(Marshal.PtrToStructure(ptr, type), SP_DRVINFO_DETAIL_DATA)
                   result.HardwareID = Marshal.PtrToStringAuto(ptrHardwareID, HardwareIDLength)
    
                   If result.CompatIDsOffset > 1 Then
                      HardwareID = Marshal.PtrToStringAuto(ptrHardwareID)
                   End If
    
                   If result.CompatIDsLength > 0 Then
                      Dim ptrCompatibleIDs = ptrHardwareID.Add(CInt(result.CompatIDsOffset) * Marshal.SystemDefaultCharSize)
                      Dim CompatibleIDs = Marshal.PtrToStringAuto(ptrCompatibleIDs, CInt(result.CompatIDsLength))
    
                      CompatibleIDsList = New List(Of String)(CompatibleIDs.Split(Convert.ToChar(0US)))
                      CompatibleIDsList.RemoveAt(CompatibleIDsList.Count - 1)
                      CompatibleIDsList.RemoveAt(CompatibleIDsList.Count - 1)
                   End If
    
                   Return New ExtendedDriverInfoDetail(result, HardwareID, CompatibleIDsList)
                Else
                   Win32.Helper.ThrowWin32Exception("SetupDiGetDriverInfoDetail")
                End If
             Finally
                Marshal.FreeHGlobal(ptr)
             End Try
          Else
             Win32.Helper.ThrowWin32Exception("SetupDiGetDriverInfoDetail")
          End If
    
       End Function
    

    I'll piece together all missing declarations from my libraries and post them.

    Oh, and the above is only the version for retrieving the data for the whole DeviceInfoSet, not for a specific device. I'll still have to write the latter one.


    Armin

  • vendredi 16 mars 2012 11:23
     
     Traitée A du code

    Missing declarations:

    <StructLayout(LayoutKind.Sequential, Pack:=0, CharSet:=CharSet.Auto)> _
    Public Structure SP_DRVINFO_DATA
       Public Size As UInt32
       Public DriverType As DriverType
       Public Reserved As UIntPtr
       <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=AZ.Win32.Constants.LINE_LEN)> Public Description As String
       <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=AZ.Win32.Constants.LINE_LEN)> Public MfgName As String
       <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=AZ.Win32.Constants.LINE_LEN)> Public ProviderName As String
       Public DriverDate As AZ.Win32.FILETIME 'ComTypes.FILETIME 
       Public DriverVersion As UInt64
    End Structure
    
    
    Public Enum DriverType As UInt32
       NoDriver = 0
       ClassDriver = 1
       CompatDriver = 2
    End Enum
    
    Public Const LINE_LEN As Integer = 256
    
    ''' <summary>
    ''' </summary>
    ''' <remarks>Attention: According to the documentation,
    ''' pointers to a FILETIME structure must
    ''' not be casted to __in64* or ULARGE_INTEGER*
    ''' due to alignment problems on 64 bit Windows.</remarks>
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure FILETIME
       Public LowDateTime As UInteger
       Public HighDateTime As UInteger
    End Structure
    
    
    Public Class ExtendedDriverInfoDetail
       Public ReadOnly Native As SP_DRVINFO_DETAIL_DATA
       Public ReadOnly HardwareID As String
    
       Private ReadOnly _CompatibleIDs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
    
       Friend Sub New( _
          ByVal Native As SP_DRVINFO_DETAIL_DATA, _
          ByVal HardwareID As String, _
          ByVal CompatibleIDs As Collections.Generic.List(Of String))
    
          Me.Native = Native
          Me.HardwareID = HardwareID
    
          If CompatibleIDs IsNot Nothing Then
             _CompatibleIDs = CompatibleIDs.AsReadOnly
          End If
    
       End Sub
       Public ReadOnly Property CompatibleIDs() As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
          Get
             Return _CompatibleIDs
          End Get
       End Property
    
    End Class
    
    
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure SP_DRVINFO_DETAIL_DATA
       Public cbSize As UInt32
       Public InfDate As AZ.Win32.FILETIME
       Public CompatIDsOffset As UInt32
       Public CompatIDsLength As UInt32
       Public Reserved As UIntPtr
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=AZ.Win32.Constants.LINE_LEN)> Public SectionName As String
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=AZ.Win32.Constants.MAX_PATH)> Public InfFileName As String
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=AZ.Win32.Constants.LINE_LEN)> Public DrvDescription As String
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=AZ.Win32.Constants.ANYSIZE_ARRAY)> Public HardwareID As String
    End Structure
    
    
    Public Const MAX_PATH As UInteger = 260
    Public Const ANYSIZE_ARRAY As UInteger = 1
    
    
       Public Declare Auto Function SetupDiGetDriverInfoDetail Lib "setupapi.dll" ( _
          ByVal hDeviceInfoSet As IntPtr, _
          ByVal DeviceInfoData As IntPtr, _
          <[In]()> ByRef DriverInfoData As SP_DRVINFO_DATA, _
          ByVal DriverInfoDetailData As IntPtr, _
          ByVal DriverInfoDetailDataSize As Int32, _
          ByRef RequiredSize As UInt32) As Boolean
    
    
    
       Public Declare Auto Function SetupDiGetDriverInfoDetail Lib "setupapi.dll" ( _
          ByVal hDeviceInfoSet As IntPtr, _
          ByVal DeviceInfoData As IntPtr, _
          <[In]()> ByRef DriverInfoData As SP_DRVINFO_DATA, _
          ByVal DriverInfoDetailData As IntPtr, _
          ByVal DriverInfoDetailDataSize As UInt32, _
          ByVal RequiredSize As IntPtr) As Boolean
    
    
    

    Just pick out what you not already have, and also let me know if something's missing.


    Armin

  • vendredi 16 mars 2012 11:26
     
     

    Addition: As reasoned in one of my last posts from yesterday, I decided to add that helper class "ExtendedDriverInfoDetail". Otherwise the native structure really wouldn't be convenient to handle.


    Armin

  • vendredi 16 mars 2012 16:00
     
     

    Hello Armin,

    Thanks for the assist.  I just woke up, yawn.  I couldn't fall alseep at all.  I can't see your actual code that calls the function very well.  Some of it scrolls out of the window and does not wrap. Could you repost the code please.

  • vendredi 16 mars 2012 17:20
     
     

    Hi and good morning, :)

    there should be a scollbar. Use another browser. ;) Chrome works well. If I post again, it would look the same.

    The calling code is nothing special; just pass the deviceinfoset handle and the SP_DRVINFO_DATA structure. The latter you get from a call to SetupDiEnumDriverInfo.

    Currently I'm busy and have to push my own project. I think the kind guys here in the forum will continue.


    Armin

  • vendredi 16 mars 2012 17:26
     
     

    OK Armin,

    Thanks, I understand.  I have to put my project on hold to deal with some family issues anyway.  I appreciate your help.