Solved

C# to VB.NET conversion

Posted on 2007-03-22
6
661 Views
Last Modified: 2008-03-17
Can anyone translate the following to VB.NET
BOOL SetupDiEnumDeviceInterfaces(
  HDEVINFO DeviceInfoSet,
  PSP_DEVINFO_DATA DeviceInfoData,
  const GUID* InterfaceClassGuid,
  DWORD MemberIndex,
  PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
);

My declaration is giving me a PInvoke error.
  Public Declare Function SetupDiEnumDeviceInterfaces Lib "Setupapi.dll" Alias _
           "SetupDiEnumDeviceInterfaces" (ByVal DeviceInfoSet As Int64, _
           ByVal DeviceInfoData As IntPtr, ByVal InterfaceClassGuid As IntPtr, _
           ByVal MemberIndex As Int32, ByVal DeviceInterfaceData As IntPtr) As Boolean

0
Comment
Question by:CASorter
6 Comments
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18777477

Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal Handle As Long, ByVal InfoPtr As Long, ByRef GuidPtr As Guid, ByVal MemberIndex As Integer, ByRef InterfaceDataPtr As SP_DEVINFO_DATA) As Intege

source:http://www.thescripts.com/forum/thread110396.html
0
 

Author Comment

by:CASorter
ID: 18780568
As the referenced website indicates, the function is not working. Still unanswered.
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 19082036
This should do it...

    Private Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" ( _
        ByVal DeviceInfoSet As IntPtr, _
        ByVal DeviceInfoData As IntPtr, _
        ByRef InterfaceClassGuid As Guid, _
        ByVal MemberIndex As Integer, _
        ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA _
    ) As Boolean

Here is an example of it in use

        Dim DiskGUID As New Guid(GUID_DEVINTERFACE_DISK)

        ' We start at the "root" of the device tree and look for all
        ' devices that match the interface GUID of a disk
        Dim h As IntPtr = SetupDiGetClassDevs(DiskGUID, 0, IntPtr.Zero, DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
        If h.ToInt32 <> INVALID_HANDLE_VALUE Then

            Dim Success As Boolean = True
            Dim i As Integer = 0
            While Success
                ' create a Device Interface Data structure
                Dim dia As New SP_DEVICE_INTERFACE_DATA
                dia.cbSize = Marshal.SizeOf(dia)

                ' start the enumeration
                Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, DiskGUID, i, dia)
                If Success Then
                    ' prepare a Devinfo Data structure
                    Dim da As New SP_DEVINFO_DATA
                    da.cbSize = Marshal.SizeOf(da)

                    ' prepare a Device Interface Detail Data structure
                    Dim didd As New SP_DEVICE_INTERFACE_DETAIL_DATA
                    didd.cbSize = 4 + Marshal.SystemDefaultCharSize ' trust me :)

                    ' now we can get some more detailed information
                    Dim nBytes As Integer = BUFFER_SIZE
                    Dim nRequiredSize As Integer = 0
                    If SetupDiGetDeviceInterfaceDetail(h, dia, didd, nBytes, nRequiredSize, da) Then

                        ' OK, let's get the Device Number again... this time using
                        ' the device's "Symbolic Name".  If the numbers match, we've
                        ' found the one we're looking for.
                        If GetDeviceNumber(didd.DevicePath) = DeviceNumber Then
                            ' Do something here
                            Exit While
                        End If
                    End If
                End If
                i += 1
            End While
        End If
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question