I've to write a Win32 program that,given a file,tells me what process uses it...tricky uh?

Perhaps i could use a cicle like this :

Code:
 for(..some condition..){
  
     LockFileEx(handle to the file to control, ...... , ... , ..... , ... );
   
     Use GetLastError() and FormatMessage() for checking if an     error has occured
   and,if it is so,then some other process is reading the file and the 
   FormatMessage() function will tell me information about that process (i think)
   if i call it with the error code returned by GetLastError()

   Otherwise , if there's no error , UnlockFileEx(.....);

}
could it work?