直接上代码:
#include "stdafx.h"
typedef struct ThreadParameter
{
LPTSTR in_directory;//监控的路径
FILE_NOTIFY_INFORMATION *in_out_notification;//存储监控函数返回信息地址
DWORD in_MemorySize;//传递存储返回信息的内存的字节数
DWORD *in_out_BytesReturned;//存储监控函数返回信息的字节数
FILE_NOTIFY_INFORMATION *temp_notification;//备用的一个参数
}ThreadParameter;
char* w2c(char *pcstr,const wchar_t *pwstr, size_t len)
{
int nlength = wcslen(pwstr);
int nbytes = WideCharToMultiByte(0,0,pwstr,nlength,NULL,0,NULL,NULL );
// make sure the buffer is big enough for this, making it larger if necessary
if(nbytes > len) nbytes = len;
// 通过以上得到的结果,转换unicode 字符为ascii 字符
WideCharToMultiByte(0,0,pwstr,nlength,pcstr,nbytes,NULL,NULL);
return pcstr ;
}
DWORD WINAPI WatchChanges(LPVOID lpParameter)
{
ThreadParameter *parameter = (ThreadParameter*)lpParameter;
LPCTSTR WatchDirectory=parameter->in_directory;//监控目录