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
Solved

C# to VB.NET conversion

Posted on 2007-03-22
6
663 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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