首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

挑战:怎么得到向usb设备拷贝的文件信息

2012-01-12 
挑战:如何得到向usb设备拷贝的文件信息如题。我上网找了好多资料,就是没有关于这方面的。基本需求是,有一个u

挑战:如何得到向usb设备拷贝的文件信息
如题。
我上网找了好多资料,就是没有关于这方面的。

基本需求是,有一个usb设备插在pc上,然后可以通过各种途径将本地计算机上的文件拷贝到usb存储设备上(鼠标菜单复制,ctrl+c复制,托拽复制)。

得到在此过程中传输的文件信息。

挑战。。。。。。。。。。。。。。。。。。。。。。。。。。。。

[解决办法]
顶,不会.想知道
[解决办法]
WINDOWS对所有外设备都是用CREATEFILE, 看看在这个API上能不能想想办法.
[解决办法]
如果是在Explorer的Shell操作可以用ICopyHook::CopyCallback,Hook到。
[解决办法]
不然usb的过滤驱动应该也可以
[解决办法]
Windows提供了函数来完成您的意图,您可以首先调用FindFirstChangeNotification来告诉系统,您的程序对于文件系统的变化消息感兴趣,此函数返回一个句柄,可以将它用于WaitForSingleObject或者WaitForMultipleObject的一些线程同步函数,一旦事件变成了有信号,便可得知文件系统有了变化,就可以漫游目录来得到新的信息。当这些处理完成后,再调用FindNextChangeNotification即可。

下面是msdn里面的一个例子程序,它的功能是监测一个目录的目录名改变和另一个目录下的文件名字的改变。

剩下的可以参考MSDN....
[解决办法]
汗。。。msdn也不自己查

DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];

// Watch the C:\WINDOWS directory for file creation and
// deletion.

dwChangeHandles[0] = FindFirstChangeNotification(
"C:\\WINDOWS ", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes

if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());

// Watch the C:\ subtree for directory creation and
// deletion.

dwChangeHandles[1] = FindFirstChangeNotification(
"C:\\ ", // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes

if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());

// Change notification is set. Now wait on both notification
// handles and refresh accordingly.

while (TRUE)
{

// Wait for notification.

dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);

switch (dwWaitStatus)
{
case WAIT_OBJECT_0:

// A file was created or deleted in C:\WINDOWS.
// Refresh this directory and restart the
// change notification. RefreshDirectory is an
// application-defined function.

RefreshDirectory( "C:\\WINDOWS ")
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;

case WAIT_OBJECT_0 + 1:

// A directory was created or deleted in C:\.
// Refresh the directory tree and restart the
// change notification. RefreshTree is an
// application-defined function.

RefreshTree( "C:\\ ");
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;

default:
ExitProcess(GetLastError());
}

热点排行