Solved

C# to VB.NET conversion

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Custom auto number 6 51
Round up to 100% in .NET 10 44
Protecting vb6 & .Net code Obfuscation 18 49
Saveas need to save a copy 16 9
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now