-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDeviceCollection.cls
More file actions
81 lines (53 loc) · 1.94 KB
/
DeviceCollection.cls
File metadata and controls
81 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "DeviceCollection"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Declare Function QueryDosDeviceW _
Lib "kernel32.dll" (ByVal lpDeviceName As Long, _
ByVal lpTargetPath As Long, _
ByVal ucchMax As Long) As Long
Private Const MAX_PATH As Long = 260
Private m_drives As Collection
Public Function ConvertToLetterPath(strPath As String)
On Error GoTo Handler
Dim letterIndex As Long: letterIndex = 1
Dim delimNumber As Long: delimNumber = 3
Dim devicePath As String
If Left(strPath, 8) = "\Device\" Then
While delimNumber > 0
letterIndex = InStr(letterIndex, strPath, "\") + 1
delimNumber = delimNumber - 1
Wend
devicePath = Mid(strPath, 1, letterIndex - 2)
strPath = Chr(m_drives(devicePath)) & ":\" & Mid(strPath, letterIndex)
End If
ConvertToLetterPath = strPath
Exit Function
Handler:
LogError Err.Description, "ConvertToLetterPath", "DeviceCollection"
End Function
Private Sub Class_Initialize()
Dim szLinkName(MAX_PATH) As Byte
Dim szDevName(MAX_PATH) As Byte
Dim bDrive As Byte: bDrive = 0
Dim sDevName As String
Set m_drives = New Collection
szLinkName(2) = AscW(":")
For bDrive = AscB("a") To AscB("z")
szLinkName(0) = bDrive
If QueryDosDeviceW(VarPtr(szLinkName(0)), VarPtr(szDevName(0)), MAX_PATH) Then
sDevName = szDevName
m_drives.Add szLinkName(0), sDevName
End If
Next
End Sub