好吧,所以我可以回答我自己的一个问题:
有没有办法让Windows同时通知我两次卷删除?
是的
-即使Windows只发送一个
DBT_DEVTYP_VOLUME
WM_DEVICECHANGE
消息,
实际上,两个卷删除都会通知您
-但是,一如既往,
the answer lies deep down buried in MSDN
:
尽管dbcv_unitmask成员可以在任何消息中指定多个卷,但这并不保证为指定的事件只生成一条消息。多个系统组件可以同时独立地为逻辑卷生成消息。
所以,我所要做的就是忽略
example function
微软提供的一个样本,
char FirstDriveFromMask (ULONG unitmask)
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}
return (i + 'A');
}
并将其替换为解释
全部的
驱动器受影响。因此,我收到的一条消息确实是针对两个卷的,而且两个卷驱动器字母都在掩码中可用。
// [IN] ULONG unitmask
// [IN/OUT] char* outDriveLetters - an array of characters to be passed in
// that is filled out with the drive letters
// in the mask (this must be 26 bytes to be safe)
// RETURNS the number of drive letters in the mask
int MaskToDriveLetters (ULONG unitmask, char* outDriveLetters)
{
int cnt = 0;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
{
outDriveLetters[cnt++] = 'A' + i;
cnt++;
}
unitmask = unitmask >> 1;
}
outDriveLetters[cnt] = 0; // set the last character to \0 (optional)
return cnt; // the number of drives that were set in the mask
}
不过,我还有另外一个问题要回答——这两条信息怎么可能(
DBT_DEVTYP_DEVICEINTERFACE
和
dbt_devtyp_卷
)是否相关?