| << 16.1.2- Why do we Use Components? | Chapter16 | 16.2.0- Writing Our Own Components >> |
How Components Work
When we refer to a component in code, the system needs to know where to look for that component. For example, consider what happens when we used the Ad Rotator component back in Chapter 11. In our ASP code, we used the Server.CreateObject method to create an instance of the Ad Rotator component, for use in our code:
Set objAR = Server.CreateObject("MSWC.AdRotator")
When the web server runs this code and finds this line of code, it knows that it needs to create an instance of the component specified by the parameter MSWC.AdRotator. At this stage, the web server doesn't know what component MSWC.AdRotator refers to – so it asks our machine's registry. The machine's registry is the place that stores information about all the components that have been registered on our machine – and it will tell the web server where to find the file that contains the executable code for the Ad Rotator component.
Let's take a quick look at the registry
now. Select Start | Run;
in the dialog box, type RegEdit and click OK
– this will start the registry viewer. Let's move straight to the entry for the
Ad Rotator component. In the left part of the registry viewer, navigate to the
node HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\
{1621F7C0-60AC-11CF-9427-444553540000}:
|
|
Here, you can see a number of important features:
- The long string of numbers and letters highlighted on the left of the screen is the ClassID (or CLSID). This string uniquely identifies the component from all other components – that is, the Ad Rotator component is the only component whose ClassID is 1621F7C0-60AC-11CF-9427-444553540000
- You'll recognize the name MSWC.AdRotator on the right-hand side of the screen as the name that we specified in the parameter of the Server.CreateObject method. This name is the component's ProgID; this is the name that the web server passed to the registry, in order to find out more information about the associated component.
The ProgID isn't guaranteed to be unique, but it is rather easier to use in our code.
If you highlight the InProcServer32 node in the registry viewer now, you'll see some more interesting information:
|
|
On the right, you can see the string C:\WINNT\System32\inetsrv\adrot.dll – this is the exact location of the .dll file that contains the executable code for the Ad Rotator component. Once the web server knows this, it can grab an instance of that component and proceed with executing the ASP page.
| << 16.1.2- Why do we Use Components? | Chapter16 | 16.2.0- Writing Our Own Components >> |

RSS


