Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9177727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:23:30+00:00 2026-06-17T17:23:30+00:00

I am declaring and calling a dll function using the following syntax in VB6:

  • 0

I am declaring and calling a dll function using the following syntax in VB6:

'Declare the function
Private Declare Sub MYFUNC Lib "mylib.dll" ()

'Call the function
MYFUNC

Calling the function results in the error File not found: mylib.dll. This happens when the application is run from the vb6 IDE or from a compiled executable.

The dll is in the working directory, and I have checked that it is found using ProcMon.exe from sysinternals. There are no failed loads, but the Intel Fortran dlls are not loaded (the ProcMon trace seems to stop before then).

I have also tried running the application in WinDbg.exe, and weirdly, it works! There are no failures on this line. The ProcMon trace shows that the Intel Fortran dlls are loaded when the program is run in this way.

The dll is compiled with Fortran Composer XE 2011.

Can anyone offer any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:23:31+00:00Added an answer on June 17, 2026 at 5:23 pm

    When loading DLLs, “file not found” can often be misleading. It may mean that the DLL or a file it depends on is missing – but if that was the case you would have spotted the problem with Process Monitor.

    Often, the “file not found” message actually means that the DLL was found, but an error occured when loading it or calling the method.

    There are actually three steps to calling a procedure in a DLL:

    1. Locate and load the DLL, running the DllMain method if present.
    2. Locate the procedure in the DLL.
    3. Call the procedure.

    Errors can happen at any of these stages. VB6 does all this behind the scenes so you can’t tell where the error is happening. However, you can take control of the process using Windows API functions. This should tell you where the error is happening. You can alse set breakpoints and use Process Monitor to examine your program’s behaviour at each point which may give you more insights.

    The code below shows how you can call a DLL procedure using the Windows API. To run it, put the code into a new module, and set the startup object for your project to “Sub Main”.

    Option Explicit
    
    ' Windows API method declarations
    Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias _
        "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, _
        ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) _
        As Long
    
    Private Declare Function FormatMessage Lib "kernel32" Alias _
        "FormatMessageA" (ByVal dwFlags As Long, lpSource As Long, _
        ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
        ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Any) _
        As Long
    
    Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
    
    Const MyFunc As String = "MYFUNC"
    Const MyDll As String = "mylib.dll"
    
    Sub Main()
    
        ' Locate and load the DLL. This will run the DllMain method, if present
        Dim dllHandle As Long
        dllHandle = LoadLibrary(MyDll)
    
        If dllHandle = 0 Then
            MsgBox "Error loading DLL" & vbCrLf & ErrorText(Err.LastDllError)
            Exit Sub
        End If
    
        ' Find the procedure you want to call
        Dim procAddress As Long
        procAddress = GetProcAddress(dllHandle, MyFunc)
    
        If procAddress = 0 Then
            MsgBox "Error getting procedure address" & vbCrLf & ErrorText(Err.LastDllError)
            Exit Sub
        End If
    
        ' Finally, call the procedure
        CallWindowProc procAddress, 0&, "Dummy message", ByVal 0&, ByVal 0&
    
    End Sub
    
    ' Gets the error message for a Windows error code
    Private Function ErrorText(errorCode As Long) As String
    
        Dim errorMessage As String
        Dim result As Long
    
        errorMessage = Space$(256)
        result = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0&, errorCode, 0&, errorMessage, Len(errorMessage), 0&)
    
        If result > 0 Then
            ErrorText = Left$(errorMessage, result)
        Else
            ErrorText = "Unknown error"
        End If
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is
I'm declaring a varchar variable in T-SQL declare @var varchar(max); I have a select
I am declaring a SQL string that looks something similar to the following: string
Quick question: If I have a very large function/sub in a class that is
I'm having some difficulty with a P/Invoke call on a C++ dll. I get
I have a 3rd party Delphi DLL which I am calling from C++. Unfortunately,
I am aware that the syntax for declaring a template class method in a
For example, if I'm declaring: internal static class WinAPI { [DllImport(DwmApi.dll, PreserveSig = false)]
Can I declare a non-member function (global function, may be) as const in C++?
The function below takes the argv[0] argument that contains the calling path of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.