tags:

views:

119

answers:

2

Originally I was linked to this call so I could log all access to a certain file and capture all the changes to it.

I have worked through several examples and have failed. Even the MSDN code doesn't compile for me.

Can someone provide me with a small working snippet to monitor a file and record changes?

Or at least some pointers?

Thanks

A: 

Check out this SO question: How to see if a subfile of a directory has changed.

Nick D
A: 

You might not have the header that declares ReadDirectoryChangesW, or you need to #define _WIN32_WINNT as greater than or equal to 0x0400. If it's the former, you can manually get the address to ReadDirectoryChangesW and call that:

HANDLE kernel32_dll_handle= LoadLibrary("kernel32.dll");
FARPROC ReadDirectoryChangesWAddress= GetProcAddress(kernel32_dll_handle, "ReadDirectoryChangesW");

typedef BOOL WINAPI (*ReadDirectoryChangesWDeclaration)(
  __in         HANDLE hDirectory,
  __out        LPVOID lpBuffer,
  __in         DWORD nBufferLength,
  __in         BOOL bWatchSubtree,
  __in         DWORD dwNotifyFilter,
  __out_opt    LPDWORD lpBytesReturned,
  __inout_opt  LPOVERLAPPED lpOverlapped,
  __in_opt     LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);

ReadDirectoryChangesWDeclaration ReadDirectoryChangesW= (ReadDirectoryChangesWDeclaration)ReadDirectoryChangesWAddress;
MSN