What is late binding?

In a nutshell, late binding is run-time resolution / dynamic loading.  Compile time resolution (sometimes called ‘early binding’), uses the compiler and linker to verify that the argument types used to call a function matches the function’s signature.  In my mind, early binding allows me to check my grammar (how I am calling functions) before checking in my code.  By contrast, late binding requires the developer to specify the function signatures and to ensure that the correct types are used.

Why is it called ‘late’ binding?  ‘Late’ refers to the fact that the binding decisions (which binary to load, which function to call) is deferred as long as possible, often until just before the function is called, rather than having the binding decisions made at compile time (early).

In C/C++, late binding (a.k.a. run-time dynamic linking) often takes the form of LoadLibrary / GetProcAddress / FreeLibrary. The MSDN Library provides a good example of late binding in C/C++.

For the .NET Framework (.NET Compact Framework included), when you use Reflection to load an assembly, you are late binding.  The MSDN Library has a nice example (in Visual Basic.NET and C#) on how to dynamically load and use types via reflection.

Why late bind?
“Run-time dynamic linking enables the process to continue running even if a DLL is not available. The process can then use an alternate method to accomplish its objective. For example, if a process is unable to locate one DLL, it can try to use another, or it can notify the user of an error.”

The above MSDN Library quote describes my favorite use for late binding — avoiding an application crash if a DLL is missing.  Another great use for late binding is enabling application plugins.

Note:  It is important to be aware that late binding can have an impact on your application’s performance.  Please be sure to measure and evaluate whether or not any performance issues take aware from any benefit(s) gained from late binding in your application.

Take care!
— DK

This posting is provided “AS IS” with no warranties, and confers no rights.

Comments (1)

  1. kamranshahid says:

    Hi David,

          I regularly see your blog.I am currently in a problem.

    I have to catch email "sent" event from pocket outlook in windows mobile 5.0 [pocket pc and smart phone both].I have search a lot but can’t find any solution to catch this event from managed or unmanaged code.

    Could you please help me out in this.