Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Linking Explicitly

With explicit linking, applications must make a function call to explicitly load the DLL at run time. To explicitly link to a DLL, an application must:

  • Call LoadLibrary (or a similar function) to load the DLL and obtain a module handle.

  • Call GetProcAddress to obtain a function pointer to each exported function that the application wants to call. Because applications are calling the DLL's functions through a pointer, the compiler does not generate external references, so there is no need to link with an import library.

  • Call FreeLibrary when done with the DLL.

For example:


HINSTANCE hDLL;               // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer
DWORD dwParam1;
UINT  uParam2, uReturnVal;

hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
   lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
   if (!lpfnDllFunc1)
      // handle the error
      return SOME_ERROR_CODE;
      // call the function
      uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
© 2015 Microsoft