title: Why does an open DLL Handle not protect file from being moved?
body: <p>I just had a surprising bug where a DLL file that was loaded using the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx"><code>LoadLibrary</code></a> API call was renamed while being loaded. Apparently, having an open DLL handle on a file does not prevent that file from being renamed, or even moved to a different path. It is however protected from deletion and being moved to a different disk. The program using the DLL <em>continues to work fine</em> if this happens. ProcessExplorer shows that the path of the DLL handle updates accordingly.</p>
  
  <p>This behavior is different from ordinary file handles in Windows. For example, when keeping an open <code>std::ifstream</code> to the same DLL, renaming is no longer allowed by the operating system. I find this behavior quite surprising and was wondering if anyone could give an explanation for it? In particular I'd be interested in the rationale for allowing this, as I'd imagine the tracking of the file on disk to be more difficult than just locking it in place. So the OS probably has to actively support this feature, which means there has to be a use case for it?</p>