关于磁盘盘符,以下代码应该有用
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_DEVICECHANGE:
Proc_WM_DEVICECHANGE(wParam,lParam);
break;
。。。。。。。。。。。。。。。。。。。。。。
void Proc_WM_DEVICECHANGE(WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL:
if (lpdb ->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
TCHAR DiskLetter[32];
DecodeDiskLetter(lpdbv->dbcv_unitmask, DiskLetter, 32);
_tcscat(DiskLetter, "://");
TCHAR VolumeName[MAX_PATH] = {0};
if(!GetVolumeNameForVolumeMountPoint(DiskLetter, VolumeName, MAX_PATH))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "GetVolumeNameForVolumeMountPoint", MB_OK);
}
if(!DeleteVolumeMountPoint(DiskLetter))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "DeleteVolumeMountPoint", MB_OK);
}
if(!SetVolumeMountPoint(_T("H://"), VolumeName))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "SetVolumeMountPoint", MB_OK);
}
}
break;
}
}
void DecodeDiskLetter(DWORD Mask, PTCHAR pOutBuffer, int outlen)
{
DWORD ecx = 0;
DWORD eax = 0;
while(ecx < 26)
{
DWORD esi = 1;
if(Mask & esi<<ecx)
{
*(pOutBuffer+eax) = (TCHAR)(ecx+_T('A'));
eax++;
}
ecx++;
}
*(pOutBuffer+eax) = _T('/0');
}
另外服务中应该注册guid,以上时通过窗口接受的
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_DEVICECHANGE:
Proc_WM_DEVICECHANGE(wParam,lParam);
break;
。。。。。。。。。。。。。。。。。。。。。。
void Proc_WM_DEVICECHANGE(WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL:
if (lpdb ->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
TCHAR DiskLetter[32];
DecodeDiskLetter(lpdbv->dbcv_unitmask, DiskLetter, 32);
_tcscat(DiskLetter, "://");
TCHAR VolumeName[MAX_PATH] = {0};
if(!GetVolumeNameForVolumeMountPoint(DiskLetter, VolumeName, MAX_PATH))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "GetVolumeNameForVolumeMountPoint", MB_OK);
}
if(!DeleteVolumeMountPoint(DiskLetter))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "DeleteVolumeMountPoint", MB_OK);
}
if(!SetVolumeMountPoint(_T("H://"), VolumeName))
{
sprintf(VolumeName, "Err %d", GetLastError());
MessageBox(NULL, VolumeName, "SetVolumeMountPoint", MB_OK);
}
}
break;
}
}
void DecodeDiskLetter(DWORD Mask, PTCHAR pOutBuffer, int outlen)
{
DWORD ecx = 0;
DWORD eax = 0;
while(ecx < 26)
{
DWORD esi = 1;
if(Mask & esi<<ecx)
{
*(pOutBuffer+eax) = (TCHAR)(ecx+_T('A'));
eax++;
}
ecx++;
}
*(pOutBuffer+eax) = _T('/0');
}
另外服务中应该注册guid,以上时通过窗口接受的