Directory Services

Early Binding Support

Here is a scenario with early binding support in place. The following code is an example.

Dim x as IADsUser
Dim y as IADsExt1
Dim z as IADsExt2
Set x = GetObject("LDAP://CN=JeffSmith, OU=Sales, 
Set y = x
y.MyNewMethod( "\\srv\public")
y.MyProperty = "Hello World"
Set z = y
z.OtherProperty = 4362
Debug.Print x.LastName
Set z = GetObject("LDAP://CN=Jeff,OU=Engr, 
z.OtherProperty = 5323

In this example, two extension components extend a user object. Each extension publishes its own interface. Each extension is not aware of the other extension interface; only ADSI is aware of the existence of both extensions. Each extension delegates its IUnknown to ADSI. ADSI acts as an aggregator for both extensions, and any other future extensions. Querying an interface from any extension, or from ADSI, yields the same consistent result.

Look at the steps required to make an extension.

Step 1: Add Aggregation to Your Component

Follow the COM specification for adding aggregation to your component. In summary, you must accept the pUnknown requests to your component during CreateInstance, and delegate the pUnknown to the aggregator's IUnknown if the component is aggregated.

Step 2: Register Your Extension

Now you must decide which directory class you want to extend. You cannot use the same interfaces to accomplish this that you would use for an ADSI interface (for example, IADsUser, IADsComputer). Directory objects are persisted in the directory, while your extension and ADSI are running on the client machine. Directory object examples are user, computer, printQueue, serviceConnectionPoint, and nTDSService. You can add a new class in Active Directory® and create a new extension for this new class as well.

You use registry keys to associate a directory class name with the ADSI extension components. The following figure represents the existing registry layout, as a well as new keys.

Note  Extension objects are still required to register standard COM keys.

HKLM |__Software     |___Microsoft             |____ADS


                            |__LDAP <continue from above>




                                  |____<CLSID of ExtensionA1>

                                        Interfaces(REG_BINARY) {List of interfaces)

                                  |____<CLSID of ExtensionA2>

                                        Interfaces(REG_BINARY) {List #1 of interfaces)

                       |____ <ClassNameB>

                                   |____<CLSID of ExtensionB1>

                                        Interfaces(REG_BINARY) {List of interfaces)

                                   |____<CLSID of ExtensionB2>

                                        Interfaces(REG_BINARY) {List #1 of interfaces)


"Interfaces"={466841B0-E531-11d1-8718-00C04FD44407} {466841B1-E531-11d1-8718-00C04FD44407}

The list of interfaces from Extension1 can be different from that of Extension2. The object, when active, supports the interfaces of the aggregator (ADSI) and all the interfaces provided by the aggregate's Extension1 and Extension2. Resolution of conflicting interfaces (the same interface supported by both the aggregator and the aggregates or by multiple aggregates) is determined by priorities of the extensions.

You can also associate your CLSID extension with multiple object class names. For example, your extension can extend both the user and contact objects.

Note  Extension behavior is added on a per-object class, not on a per-object instance.

It is best to register your extensions, as you would any other COM components, with a call to the DllRegisterSvr function. You should also provide a facility to unregister your extension with the DllUnregisterServer function.

The following example shows how to register an extension.

// Register the class.
hr = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
 &dwDisposition );
// Register the Interface.
const TCHAR szIf[] = _T("{E1E3EDF7-48D1-11D2-B22B-0000F87A6B50}");
hr = RegSetValueEx( hKey, _T("Interfaces"), 0, REG_BINARY, (const BYTE *) szIf, sizeof(szIf) );
return S_OK;