# Early Binding in COM

**URL:** <https://www.ruby-forum.com/t/early-binding-in-com/63750>\
**Category:** Ruby\
**Created:** [June 18, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/early-binding-in-com/63750 "2006-06-18T19:20:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [June 18, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/early-binding-in-com/63750/1 "2006-06-18T19:20:53Z")

</div>

Reading the instructions of IEC.py[\*] (which perhaps I’d port to  
Ruby) I see they suggest to run something to be able to use early  
binding. Is there something analogous for Ruby? I browser the docs of  
WIN32OLE that offer some methods, but the usage in IEC.py is  
transparent to this.

– fxn

[\*] [Mayukh's World](http://www.mayukhbose.com/python/IEC/index.php)

Tuning Performance

An issue with using COM objects in Python, is the matter of Late  
Binding vs. Early Binding. Basically, there are two ways that a  
Python COM object can access its methods and properties. These two  
methods are called Late Binding and Early Binding. If a Python COM  
object uses Late Binding, then every time you access a method or  
property of the object, it goes through the IDispatch interface to  
find the method/property, even if it is the same one being called  
each time. With Early Binding, we let Python know ahead of time, what  
methods and properties are available to an object. This speeds up  
things significantly, especially inside loops, and the performance  
gains are actually quite substantial. To enable Early Binding for the  
Internet Explorer object, we need to import the Internet Explorer  
library. To do this:

```
 * In PythonWin, go to Tools --> COM Makepy Utility

 * In the dialog box that pops up, scroll down till you reach

```

Microsoft Internet Controls. If there are multiple versions, simply  
pick the latest one.

```
 * Click on the OK button. The PythonWin environment will freeze

```

for a little bit, while the library is being imported. In a little  
while, you should see a message on the Interactive Window that says  
that a file was generated.

```
 * You've successfully generated a Python type library for

```

Internet Explorer. From now on, Python will automatically use the  
type library to early-bind any Internet Explorer objects.

You can get by without importing the Internet Explorer library, but  
the performance gains are well worth it.

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [June 19, 2006, 8:00am UTC](https://www.ruby-forum.com/t/early-binding-in-com/63750/2 "2006-06-19T08:00:50Z")

</div>

Xavier N. wrote:

> Reading the instructions of IEC.py[\*] (which perhaps I’d port to  
> Ruby) I see they suggest to run something to be able to use early  
> binding. Is there something analogous for Ruby? I browser the docs of  
> WIN32OLE that offer some methods, but the usage in IEC.py is  
> transparent to this.
> 
> – fxn
> 
> [\*] [Mayukh's World](http://www.mayukhbose.com/python/IEC/index.php)
> 
> Tuning Performance
> 
> An issue with using COM objects in Python, is the matter of Late  
> Binding vs. Early Binding.

Ruby is a late binding environment.  
You get the same possibilities rather it’s early or late binding.

require “win32ole”

ie = WIN32OLE.new(“InternetExplorer.Application”)  
ie.visible = true  
ie.Navigate(“[http://www.google.com](http://www.google.com)”)

The Ruby WIN32OLE is very, very good. You should give it a try.  
I know that early binding is faster(performance wise) than late binding,  
but for now, that’s all Ruby offers.

But it gets the job done.
