[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# to VB.NET conversion

Posted on 2007-03-22
6
Medium Priority
?
670 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:K V
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 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