Friday, February 8, 2008

Solving the "Error 53: File not Found" When Calling a DLL Function from Visual Basic 6

Though I may one day come to deny it, I have been working on a Visual Studio 6 project for the past four months. Yesterday, one of our Visual Basic clients (entitled with rendering data files downloaded from an FTP connection) started reporting some Error 53: File not Found every time it would attempt to call functions defined in one of our C++ DLL's. The strange bit was that the client had no trouble linking to older versions of that library, while our other VB client (entitled with rendering files read from the local disk) wouldn't complain about even the new version.

After some googling I got to this article from Microsoft's Knowledge Base, according to which there are actually two scenarios where linking to a DLL will fail with a File not Found message:
  1. Windows is unable to load the specified DLL, particularly if the DLL has not been saved at the specified location;

  2. The dependency files required by the DLL file are not installed in the computer.
From what we gather that the VB Runtime is happy to blurt File not Found whenever it cannot load a DLL, regardless of the actual cause. At any rate, the article also mentions Dependency Walker, a tool from the Visual Studio suite, which could be used to identify any missing dependencies. And in fact, there was a dependency that wasn't being met on the first client's location – and neither should it, since it was related to a functionality implemented only in the second client. From there it was merely a question of correcting the build process (which generates customized versions of the DLL for the two clients), and everything went back to normal in Visual Studio land.