"File Not Found" error when calling an external DLL-VBForums
Results 1 to 6 of 6

Thread: "File Not Found" error when calling an external DLL

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    1

    "File Not Found" error when calling an external DLL

    I'm calling an external function from a DLL called verywrite.dll using the following line:

    Private Declare Function VeryCreate Lib "verywrite.dll" (ByVal lpFileName As String) As Long

    When running the script, the code breaks on "id = VeryCreate(szPDFFilename)" with the error "File not found". I have placed the verywrite.dll file (which contains the verycreate function) within the same directory of the Access Database I'm running. I have also tried placing it in system32 with no luck. The last thing I tried is the full path name to the file instead of just calling verywrite.dll in the declaration. Any ideas as to what I'm doing wrong or how to do this better? Thanks in advance!
    Last edited by jimithing1980; Dec 27th, 2006 at 12:31 PM.

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: "File Not Found" error when calling an external DLL

    dlls usually register in the System32 directory. True you can use one in any location but when your calling an API function like that it will only look in the System32 directory. You can place the full path to the dll in the API declaration but it wil not accept variables or dynamic strings.

    Best solution is to register the dll and place int he System32 dir.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  3. #3
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: "File Not Found" error when calling an external DLL

    Also, from MSDN.
    Dynamic-Link Library Redirection

    Problems can occur when an application loads a version of a DLL other than the one with which it shipped. Starting with Windows 2000, you can ensure that your application uses the correct version of a DLL by creating a redirection file. The contents of a redirection file are ignored, but its presence forces all DLLs in the application's directory to be loaded from that directory.

    The redirection file must be named as follows:

    appname.local

    For example, if the application's name is editor.exe, the redirection file is named editor.exe.local. You must install editor.exe.local in the same directory that contains editor.exe. You must also install the DLLs in the same directory.

    The LoadLibrary and LoadLibraryEx functions change their search sequence if a redirection file is present. If a path is specified and there is a redirection file for the application, these functions search for the DLL in the application's directory. If the DLL exists in the application's directory, these functions ignore the specified path and load the DLL from the application's directory. If the module is not in the application's directory, these functions load the DLL from the specified directory.

    For example, an application c:\myapp\myapp.exe calls LoadLibrary using the following path:

    c:\program files\common files\system\mydll.dll.

    If c:\myapp\myapp.exe.local and c:\myapp\mydll.dll exist, LoadLibrary will load c:\myapp\mydll.dll. Otherwise, LoadLibrary will load c:\program files\common files\system\mydll.dll.

    Note It is good practice to install your application's DLLs in the same directory that contains the application, even if you are not using redirection. It ensures that installing your application will not overwrite other copies of the DLL and cause other applications to fail. In addition, other applications will not overwrite your copy of the DLL and cause your application to fail.

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: "File Not Found" error when calling an external DLL

    I dont ever recal MS promoting dll files to be installed in the app path. Seems like asking for trouble.

    I recal that by default Windows searches a specific location order when looking for a dll.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  5. #5
    New Member
    Join Date
    Jan 2007
    Location
    Englishman in Malaysia
    Posts
    2

    Re: "File Not Found" error when calling an external DLL

    I believe the default order for searching is from the PATH environment variable. The re-direction method along with the putting the dll or OCX in the app path, allows the use of legacy (aka old stuff!!) modules to be used and will protect your version of a popular third party control from getting overidden in system32.

  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: "File Not Found" error when calling an external DLL

    I believe its the app.apth is searched first. Then System32, Windows, amoung other areas.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.