Good suggestion.  Unfortunately, the given filename is a wide-char string returned from ReadDirectoryChangeW() with a length but no null-terminator.  Consequently, as-is, the non-null-terminated string isn't valid for wcsdup().

Having said that, I did notice that I named the variable as 'lpwszFilename', which implies a null-terminator (which it isn't).  As such, I'll go ahead and rename it to 'lpFilename' to avoid any confusion.