Solved

C# to VB.NET conversion

Posted on 2007-03-22
6
664 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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