私は、PC ですべての USB 外部挿入を取得する方法を使用しています。vb6 で書き込み関数を使用し、dll を作成します。C++ プログラムで dll を使用したいのですが、getObject() 関数に関するエラーがあります。vb6 の dll 書き込みで getObject() を使用できますか? これは関数のコードです
Public Function GetUsbDeviceList() As String
Dim ComputerName As String
Dim wmiServices As Object
Dim wmiDiskPartitions As Object
Dim wmiDiskPartition As Object
Dim wmiDiskDrives As Object
Dim wmiDiskDrive As Object
Dim wmiLogicalDisks As Object
Dim wmiLogicalDisk As Object
Dim Vol As Object
Dim strFound As String
Dim Query As String
ComputerName = "."
Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
strFound = ""
' Get physical disk drive
Set wmiDiskDrives = wmiServices.ExecQuery("SELECT * FROM Win32_DiskDrive where InterfaceType = 'USB'")
For Each wmiDiskDrive In wmiDiskDrives
'MsgBox ("Disk drive Caption: " & wmiDiskDrive.Caption & vbNewLine & "DeviceID: " & " (" & wmiDiskDrive.DeviceID & ")")
'Use the disk drive device id to find associated partition
Query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Set wmiDiskPartitions = wmiServices.ExecQuery(Query)
For Each wmiDiskPartition In wmiDiskPartitions
'Use partition device id to find logical disk
Set wmiLogicalDisks = wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
'MsgBox ("Drive letter associated with disk drive = " & wmiDiskDrive.Caption & wmiDiskDrive.DeviceID & vbNewLine & " Partition = " & wmiDiskPartition.DeviceID & vbNewLine & " is " & wmiLogicalDisk.DeviceID)
Dim DatiUnita As Scripting.FileSystemObject
Set DatiUnita = GetObject(, "Scripting.FileSystemObject")
Set Vol = DatiUnita.GetDrive(DatiUnita.GetDriveName(wmiLogicalDisk.DeviceID))
strFound = strFound + wmiLogicalDisk.DeviceID + "," + Vol.volumename + "," + wmiDiskDrive.PNPDeviceID + ";"
Next
Next
Next
GetUsbDeviceList = strFound
End Function