This help topic has reference to my code posted here :
http://www.autohotkey.com/forum/viewtop ... 8203#98203
When A CD/DVD is inserted in a drive, WM_DEVICECHANGE is broadcast with with
wParam as
0x8000 ( DBT_DEVICEARRIVAL ) and
lParam will be a pointer to DEV_BROADCAST_VOLUME stucture.
The 4th member of DEV_BROADCAST_VOLUME stucture is
dbcv_unitmask, a DWord whose bits have to be evaluated to ascertain the CD/DVD drive letter.
dbcv_unitmask should contain integers for respective drive letters as follows:
Code:
A = 00000000000000000000000000000001 = 1
B = 00000000000000000000000000000010 = 2
C = 00000000000000000000000000000100 = 4
D = 00000000000000000000000000001000 = 8
E = 00000000000000000000000000010000 = 16
F = 00000000000000000000000000100000 = 32
G = 00000000000000000000000001000000 = 64
H = 00000000000000000000000010000000 = 128
I = 00000000000000000000000100000000 = 256
J = 00000000000000000000001000000000 = 512
K = 00000000000000000000010000000000 = 1024
L = 00000000000000000000100000000000 = 2048
M = 00000000000000000001000000000000 = 4096
N = 00000000000000000010000000000000 = 8192
O = 00000000000000000100000000000000 = 16384
P = 00000000000000001000000000000000 = 32768
Q = 00000000000000010000000000000000 = 65536
R = 00000000000000100000000000000000 = 131072
S = 00000000000001000000000000000000 = 262144
T = 00000000000010000000000000000000 = 524288
U = 00000000000100000000000000000000 = 1048576
V = 00000000001000000000000000000000 = 2097152
W = 00000000010000000000000000000000 = 4194304
X = 00000000100000000000000000000000 = 8388608
Y = 00000001000000000000000000000000 = 16777216
Z = 00000010000000000000000000000000 = 33554432
[ = 00000100000000000000000000000000 = 67108864
\ = 00001000000000000000000000000000 = 134217728
] = 00010000000000000000000000000000 = 268435456
^ = 00100000000000000000000000000000 = 536870912
_ = 01000000000000000000000000000000 = 1073741824
` = 10000000000000000000000000000000 = 2147483648
My DVD-Writer shows as
H: in explorer so I expect
dbcv_unitmask to be
128, whereas it is
2147483776 for me in Windows 2000 SP4. Inspecting the bits, I find the MSB is ON making it a signed integer!
My
previous code runs flawlessly in
Windows 98 SE and
Windows XP Pro ( SP 2) but troubles me with the said effect in
Windows 2000To workaround this effect, I have the choice of
1) Setting the first 6 bits of
dbcv_unitmask to be zero
2) Scan bits of
dbcv_unitmask from LSB to MSB, find the first bit ON and ignore the rest.
I opted for the 2nd and here is the code: (
requires 1.0.47+ )
Ascertaining drive letter on CD/DVD insert notification:Code:
OnMessage( 0x219, "WM_DEVICECHANGE" )
Return
WM_DEVICECHANGE( wParam, lParam ) { ; http://msdn2.microsoft.com/en-us/library/aa363480.aspx
Global Drv
Static DBT_DEVICEARRIVAL := 0x8000 ; http://msdn2.microsoft.com/en-us/library/aa363205.aspx
Static DBT_DEVTYP_VOLUME := 0x2 ; http://msdn2.microsoft.com/en-us/library/aa363246.aspx
/*
When wParam is DBT_DEVICEARRIVAL lParam will be a pointer to a structure identifying the
device inserted. The structure consists of an event-independent header,followed by event
-dependent members that describe the device. To use this structure, treat the structure
as a DEV_BROADCAST_HDR structure, then check its dbch_devicetype member to determine the
device type.
*/
dbch_devicetype := NumGet(lParam+4) ; dbch_devicetype is member 2 of DEV_BROADCAST_HDR
If ( wParam = DBT_DEVICEARRIVAL AND dbch_devicetype = DBT_DEVTYP_VOLUME )
{
; Confirmed lParam is a pointer to DEV_BROADCAST_VOLUME and should retrieve Member 4
; which is dbcv_unitmask
dbcv_unitmask := NumGet(lParam+12 )
; The logical unit mask identifying one or more logical units. Each bit in the mask corres
; ponds to one logical drive.Bit 0 represents drive A, Bit 1 represents drive B, and so on
Loop 32 ; Scan Bits from LSB to MSB
If ( ( dbcv_unitmask >> (A_Index-1) & 1) = 1 ) ; If Bit is "ON"
{
Drv := Chr(64+A_Index) ; Set Drive letter
Break
}
SetTimer, DriveData, -1
}
Return TRUE
}
DriveData:
DriveGet, Type , Type , %Drv%:
DriveGet, Label , Label , %Drv%:
DriveGet, Serial, Serial, %Drv%:
MsgBox, 262144, Media Insert Notification [ Drive %Drv%: ]
, Type:`t%Type%`nLabel:`t%Label%`nSerial:`t%Serial%
Return
The above now works in all the 3 OS' flawlessly but still I am a
bit uncomfortable
Am I missing something ?
