Application can call a DLL function in two ways.

  • Implicit Call
  • Explicit Call

Implicit Calling: When application or client uses its import table to call the external symbol/functions, it is called implicit call. In implicit call application use prototype header and import library to link an external symbol.
Example:
Suppose math library has a import function add()

#include "math.h"
int c = add(a, b);

Explicit Calling: When application does not links the external symbol by import library rather it loads the DLL at runtime. It does the same mechanism as operating system does during loading of the implicit linked DLL calls.

This is done by using Win32 APIs like :

  • LoadLibrary() - loads and links a input library form the DLL path, or current path,
  • GetProcAddress() - finds the symbol/function address by its name for a loaded DLL
  • FreeLibrary() - unloads the loaded DLL instance
/*Example of Explicit Call*/
typedef (add_proc)(int a, int b);
int main(int argc, char *argv[])
{
  add_proc *add;
  HANDLE h_dll;
  int a = 1, b = 2, c;
  h_dll = LoadLibrary("math.dll");/*Explicit Load*/
  if(h_dll)
  {
    add = GetProcAddress(h_dll, "add");
    if(add)
    {
      c = add(a, b); /*Explicit Call*/
    }
    else
    {
      printf("add() not found in math.dll");
    }
    FreeLibrary(h_dll);
  }
  else
  {
    printf("Unable to load math.dll");
    exit(-1);
  }
}

About our authors: Team EQA

You have viewed 1 page out of 27. Your DLL learning is 0.00% complete. Login to check your learning progress.

#