![]() |
|
![]() |
| LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Junior Member Join Date: Feb 2006 Location: India
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 4 | 1. What's the difference between early binding and late binding ? |
| | |
| | #2 (permalink) |
| Member Join Date: Feb 2006 Location: India
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 4 | i m not sure but tht wht i know............... early binding is done at compile time and late binding is done at run time |
| | |
| | #3 (permalink) |
| Technical GURU Join Date: Feb 2006 Location: India
Posts: 804
Blog Entries: 2 Thanks: 4
Thanked 35 Times in 24 Posts
Rep Power: 17 | HI, lucky_kk20 you are absolutely correct ... Early binding is done during Compile time . Late binding is done during Run time .
__________________ BINNY |
| | |
| | #4 (permalink) |
| Member Join Date: Feb 2006 Location: India Age: 28
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 4 | What is Binding?Binding is a process of matching function calls written by the programmer to the actual code (internal or external) that implements the function. It is done when the application is compiled, and all functions called in code must be bound before the code can be executed.To understand the process, think of "binding" in terms of publishing a book. Imagine your code is like the text of the book where in a certain paragraph you have written something like "see chapter 12, page x for more details." You don't know what the page number is until the book is finished, so before the paragraph can be read as intended, all the pages of the book must be bound together and the correct page number inserted into the paragraph. You wait for the book to be "bound" before you can reference other parts of the book. Binding software is similar. Your code is made up of parts that need to be pulled together before the code can be "read." Binding is the act of replacing function names with memory addresses (or memory offsets, to be more precise) where the code will "jump to" when the function is called. For COM objects, the address is a memory offset in a table of pointers (called the v-table) held by the object. When a COM function is bound, it is bound through the v-table. The structure of a COM object is simple. When your code holds a reference to an object, it holds an indirect pointer to the top of the v-table. The v-table is an array of memory addresses where each entry is a different function that can be called on that object. To call the third function on a COM object, you jump down three entries in the table and then jump to the memory location given there. That executes the code for the function and, when complete, returns you back ready to execute the next line of code. +-[Code]------------+ +.................................[COM Object]...+ | | : +-------------+ : |Set obj = Nothing -|--->| obj pointer | : | | : +-|-----------+ : +-------------------+ : | +-----------------+ : : +-->| v-table pointer | : : +--|--------------+ : : | : : | +----------------------------+ : : (3rd) | | Function 1 Address pointer | : : (Offset) | +----------------------------+ : : | | Function 2 Address pointer | : : | +----------------------------+ : : +->| Function 3 Address pointer | : : +----------------------------+ : +................................................+ The example above shows what happens when releasing a COM object. Because all COM objects inherit from IUnknown, the first three entries in the table are the methods to IUnknown. When you need to free an object, your code calls the third function in the v-table (IUnknown::Release). Fortunately, this work is done by Visual Basic behind the scenes. As a Visual Basic programmer, you never have to deal with a v-table directly. But, this structure is how all COM objects are bound, and it is important that you are familiar with it to understand what binding is. Early BindingThe example above is what is known as early (or v-table) binding. For all COM objects, this form of binding takes place whenever a COM object's IUnknown interface is called. But what about the other functions of the object? How do you call its Refresh method or its Parent property? These are custom functions that are typically unique to an object. If their locations in the v-table cannot be assumed, how do you find the function addresses needed to call them?The answer, of course, depends on whether or not you know in advance what the object's v-table looks like. If you do, you can perform the same early-binding process to the object's custom methods as you did to its IUnknown methods. This is what is generally meant by "early-binding." To use early binding on an object, you need to know what its v-table looks like. In Visual Basic, you can do this by adding a reference to a type library that describes the object, its interface (v-table), and all the functions that can be called on the object. Once that is done, you can declare an object as being a certain type, then set and use that object using the v-table. For example, if you wanted to Automate Microsoft Excel using early binding, you would add a reference to the "Microsoft Excel 8.0 Object Library" from the Project|References dialog, and then declare your variable as being of the type "Excel.Application." From then on, all calls made to your object variable would be early bound: ' Set reference to 'Microsoft Excel 8.0 Object Library' inThis method works great most of the time, but what if you don't know the exact object you will be using at design time? For example, what if you need to talk to multiple versions of Excel, or possibly to an "unknown" object altogether? Late BindingCOM includes IDispatch. Objects that implement IDispatch are said to have a dispinterface (if it is the only interface they support) or dual interface (if they also have a custom interface that you can early bind to). Clients that bind to IDispatch are said to be "late bound" because the exact property or method they are calling is determined at run time using the methods of IDispatch to locate them. Going back to the book example earlier, think of it as being like a footnote that directs you to the table of contents where you have to "look up" the page number at "read time" rather than having it already printed there in the text.The magic of the interface is controlled by two functions: GetIDsOfNames and Invoke. The first maps function names (strings) to an identifier (called a dispid) that represents the function. Once you know the ID for the function you want to call, you can call it using the Invoke function. This form of method invocation is called "late binding." Again, in Visual Basic the way you specify how the object is bound is by your object declaration. If you declare an object variable as "Object" you are, in fact, telling Visual Basic to use IDispatch, and are therefore late binding: ' No reference to a type library is needed to use late binding.As you can see, the rest of your code is the same. The only difference between early binding and late binding (in terms of the code you write) is in the variable declaration.It is important to note that what is "late bound" is the function being called and not the way it is called. From the earlier discussion on binding in general, you should notice that IDispatch itself is "early bound:" that is to say that Visual Basic makes the call to set the Visible property through a v-table entry (IDispatch::Invoke) as it would any COM call. The COM object itself is responsible for forwarding the call to the correct function to make Excel visible. This indirection allows the Visual Basic client to be compiled (that is, bound to a valid function address) but still not know the exact function that will actually do the work.
__________________ From -- Hemanth, Nellore. A.P |
| | |
| | #5 (permalink) |
| Member Join Date: Mar 2006
Posts: 56
Thanks: 0
Thanked 3 Times in 1 Post
Rep Power: 4 | when a method call is linked with method body at the compile time then it is called early binding.if it is linked at the run time then it is called latebinding . |
| | |
| | #6 (permalink) | |||||||||
| Senior Member Join Date: Feb 2006 Location:
Posts: 476
Thanks: 0
Thanked 3 Times in 3 Posts
Rep Power: 9 |
| |||||||||
| | | |||||||||
![]() |
| Tags |
| difference , thesr , whats |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| More Interview Questions Here... |