阅读:2081回复:6
函数ReadDirectoryChangesW在VC6.0下调用时总是总是报没有定义?
函数ReadDirectoryChangesW在VC6.0下调用时总是总是报没有定义?
|
|
最新喜欢:![]() |
沙发#
发布于:2002-11-08 18:51
这是UNICODE版本的函数,你需要定义_UNICODE或UNICODE宏才能有效。
|
|
|
板凳#
发布于:2002-11-08 20:51
最好两个都定义。 :D
|
|
地板#
发布于:2002-11-08 23:15
如何定义_UNICODE或UNICODE宏?能给我点例程吗?
|
|
地下室#
发布于:2002-11-09 13:43
如何定义_UNICODE或UNICODE宏?能给我点例程吗? 你可以不定义,只要把后面的一个W去掉即可,即: ReadDirectoryChanges 如果硬要定义的话,需要在#include \"windows.h\"加上 #define _UNICODE 或者在Prject->Settings->C/C->Preprosessor definitions中加上 _UNICODE或UNICODE即可。 [编辑 - 11/9/02 by Tom_lyd] |
|
|
5楼#
发布于:2002-11-18 10:00
Please try #include <TCHAR.H>
|
|
6楼#
发布于:2002-11-18 10:30
MSDN的例子:
FWATCH.C /********************************************************************** File name: fwatch.c Main source file for sample demonstrating use of file change notification APIs. Functions: CheckChangedFile() - Gets and displays change information HandleDirectoryChange() - Watch function WatchDirectories() - Starts the watch main() - Program main Written by Microsoft Product Support Services, Windows Developer Support. Copyright 1996 - 1998 Microsoft Corporation. All rights reserved. **********************************************************************/ #define UNICODE #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #define MAX_DIRS 10 #define MAX_FILES 255 #define MAX_BUFFER 4096 // this is the all purpose structure that contains // the interesting directory information and provides // the input buffer that is filled with file change data typedef struct _DIRECTORY_INFO { HANDLE hDir; TCHAR lpszDirName[MAX_PATH]; CHAR lpBuffer[MAX_BUFFER]; DWORD dwBufLength; OVERLAPPED Overlapped; }DIRECTORY_INFO, *PDIRECTORY_INFO, *LPDIRECTORY_INFO; DIRECTORY_INFO DirInfo[MAX_DIRS]; // Buffer for all of the directories TCHAR FileList[MAX_FILES*MAX_PATH]; // Buffer for all of the files DWORD numDirs; /********************************************************************** CheckChangedFile() Purpose: This function prints out information when one of the files we are watching is changed. Parameters: LPDIRECTORY_INFO lpdi - Information about the watched directory PFILE_NOTIFY_INFORMATION lpfni - Information about modified file Return Value: None Comments: ********************************************************************/ void WINAPI CheckChangedFile( LPDIRECTORY_INFO lpdi, PFILE_NOTIFY_INFORMATION lpfni) { TCHAR szFullPathName[MAX_PATH]; TCHAR *p; HANDLE hFile; FILETIME LocalFileTime; SYSTEMTIME SystemTime; BY_HANDLE_FILE_INFORMATION FileInfo; p = FileList; while(*p && lstrcmpi(p,lpfni->FileName)) p+=(lstrlen(p)+1); if(*p) { lstrcpy( szFullPathName, lpdi->lpszDirName ); lstrcat( szFullPathName, L\"\\\\\" ); lstrcat( szFullPathName, lpfni->FileName ); // we assume that the file was changed, since // that is the only thing we look for in this sample wprintf( L\"%s changed,\", szFullPathName ); hFile=CreateFile( szFullPathName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0); GetFileInformationByHandle( hFile, &FileInfo ); FileTimeToLocalFileTime( &(FileInfo.ftLastWriteTime), &LocalFileTime ); FileTimeToSystemTime( &LocalFileTime, &SystemTime ); wprintf( L\" Size = %d bytes,\", FileInfo.nFileSizeLow ); wprintf( L\" Last Access = %02d/%02d/%02d %02d:%02d:%02d\", SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond ); CloseHandle( hFile ); wprintf( L\"\\n\" ); } } /********************************************************************** HandleDirectoryChanges() Purpose: This function receives notification of directory changes and calls CheckChangedFile() to display the actual changes. After notification and processing, this function calls ReadDirectoryChangesW to reestablish the watch. Parameters: HANDLE hCompPort - Handle for completion port Return Value: None Comments: ********************************************************************/ void WINAPI HandleDirectoryChange( DWORD dwCompletionPort ) { DWORD numBytes; DWORD cbOffset; LPDIRECTORY_INFO di; LPOVERLAPPED lpOverlapped; PFILE_NOTIFY_INFORMATION fni; do { // Retrieve the directory info for this directory // through the completion key GetQueuedCompletionStatus( (HANDLE) dwCompletionPort, &numBytes, (LPDWORD) &di, &lpOverlapped, INFINITE); if ( di ) { fni = (PFILE_NOTIFY_INFORMATION)di->lpBuffer; do { cbOffset = fni->NextEntryOffset; if( fni->Action == FILE_ACTION_MODIFIED ) CheckChangedFile( di, fni ); fni = (PFILE_NOTIFY_INFORMATION)((LPBYTE) fni + cbOffset); } while( cbOffset ); // Reissue the watch command ReadDirectoryChangesW( di->hDir,di->lpBuffer, MAX_BUFFER, TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &di->dwBufLength, &di->Overlapped, NULL); } } while( di ); } /********************************************************************** WatchDirectories() Purpose: This function implements the ReadDirectoryChangesW API for indicated directories. For each directory watched, a thread is created which waits for changes to the directory. This function waits for the user to input \'q\', then cleans up and quits. Parameters: HANDLE hCompPort - Handle for completion port Return Value: None ********************************************************************/ void WINAPI WatchDirectories( HANDLE hCompPort ) { DWORD i; DWORD tid; HANDLE hThread; // Start watching each of the directories of interest for (i=0;i<numDirs;i++) { ReadDirectoryChangesW( DirInfo.hDir, DirInfo.lpBuffer, MAX_BUFFER, TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &DirInfo.dwBufLength,&DirInfo.Overlapped, NULL); } // Create a thread to sit on the directory changes hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) HandleDirectoryChange, hCompPort, 0, &tid); // Just loop and wait for the user to quit while (getch() != \'q\'); // The user has quit - clean up PostQueuedCompletionStatus( hCompPort, 0, 0, NULL ); // Wait for the Directory thread to finish before exiting WaitForSingleObject( hThread, INFINITE ); CloseHandle( hThread ); } /********************************************************************** main() Purpose: Main entry-point for fwatch sample. This function reads an .ini file (fwatch.ini) to determine which directories and files to watch. For each directory watched some information is gathered and stored. Return Value: (see errors.h for description) None Comments: ********************************************************************/ void main(int argc, char *argv[]) { TCHAR *p,*q; // Temporary String Pointer HANDLE hCompPort=NULL; // Handle To a Completion Port DWORD i; // You always need an I. TCHAR DirList[MAX_DIRS*MAX_PATH]; // Buffer for all of the directories TCHAR IniFile[MAX_PATH]; TCHAR FilePath[MAX_PATH]; HANDLE hFile; GetCurrentDirectory( MAX_PATH, IniFile ); lstrcat( IniFile, L\"\\\\fwatch.ini\" ); GetPrivateProfileString( L\"Directories\", NULL, NULL, DirList, MAX_DIRS*MAX_PATH, IniFile ); GetPrivateProfileString( L\"Files\", NULL, NULL, FileList, MAX_FILES*MAX_PATH, IniFile ); wprintf( L\"Watching these directories:\\n\" ); // First, walk through the raw list and count items, creating // an array of handles for each directory for (p=DirList;*p!=\'\\0\';numDirs++,p+=(lstrlen(p)+1)) { |
|
|