1

Ok so I am trying to write something which can scan through a folder and identify files with a Zone.Identifier tag and delete the tag (hopefully). I've been looking at ways to do it and I'm trying out several different methods.

I have a function which uses BackupRead() etc, however I am a bit of a rookie to this kind of thing and while I've managed to find the stream with this method I was hoping to use FindFirstStreamW() to make life easier, or at least learn more about this in general.

Below is my first attempt to use this:

int
StreamsFunctionAlt (
   LPCTSTR     lpFileName )
{
   LPVOID               lpFindStreamData;
   HANDLE               hFindStream;
   STREAM_INFO_LEVELS   InfoLevel;
   DWORD                dwFlags;
   HANDLE               hFile;

    if ( !FileExists ( lpFileName ))
    {
       return 1;
    }

   lpFindStreamData = NULL;
   InfoLevel = 0;
   dwFlags = 0;

   hFindStream = FindFirstStreamW ( lpFileName,
                                    InfoLevel,
                                    lpFindStreamData,
                                    dwFlags );
   if ( !hFindStream == INVALID_HANDLE_VALUE )
   {
      FindNextStreamW ( hFindStream,
                        lpFindStreamData );
   }

   FindClose ( hFindStream );
   return 0;
}

What I'm seeing is lpFindStreamData is set to NULL and stays NULL and FindFirstStreamW() returns0xffffffff which I think I'm safe in assuming isn't what I want. lpFileName is the correct file name, and is the path to a file with an alternate stream.

As mentioned, I am a rookie, new to C and new to the windows API so if I'm using this incorrectly, have made some kind of embarrassingly silly error or you think I'm barking up the wrong tree then please let me know.

Adwo
  • 171
  • 1
  • 10

2 Answers2

1

The second parameter specifies the type of the third parameter. In this case the only info level is FindStreamInfoStandard which specifies that the data parameter should be a WIN32_FIND_STREAM_DATA.

Luke
  • 11,211
  • 2
  • 27
  • 38
1

FindFirstStreamW does not allocate a buffer for you. You must allocate the buffer yourself and pass a pointer to it:

WIN32_FIND_STREAM_DATA findStreamData;

hFindStream = FindFirstStreamW (lpFileName,
                                InfoLevel,
                                &findStreamData,
                                dwFlags );
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158