The most common way binding to an Active Directory object, by using the GetObject function, happens between an ADSI client and an ADSI provider and is also the easiest way to show how the provider component receives requests and services them. Both the ADSI API function ADsGetObject or the Visual Basic GetObject follow the same steps.
For this example, assume the ADSI client is an ADSI viewer application that has received the ADsPath "Sample://Seattle/Redmond/AnneA" from its user interface (1). The following figure details the sequence of events by numbering the flow arrows.
ADSI Components: Detailed View
In the preceding figure, the client initiates the request for an interface pointer on the Active Directory object represented by the ADsPath "Sample://Seattle/Redmond/AnneA" from the ADSI services (2). The services software, during its initialization, populated a table of installed provider programmatic identifiers (ProgIDs) from the registry ("LDAP:","Sample:", "WinNT:","NDS:", etc.) and paired them with the matching CLSIDs, which identify the appropriate software module.
The ADSI server makes sure the ProgID, in this case "Sample:", exists in the ADsPath. It then creates a bind context to optimize further references to this object, and calls the standard COM function MkParseDisplayName to create a COM moniker that can be used to find and bind to the object representing user "AnneA".
(In the following discussion, the file names of the example provider component source code are included in parentheses where appropriate.)
As in other COM server implementations, MkParseDisplayName examines the ProgID, and looks up the proper CLSID in the registry (3) to find the corresponding provider-supplied class factory code (cprovcf.cpp) in the appropriate provider implementation (4). This code creates an initial object that implements the IParseDisplayName::ParseDisplayName method (cprov.cpp). The provider's implementation of ParseDisplayName resolves the path name in the provider's own namespace. This eventually calls ADsObject and invokes the parser supplied with the provider component (parse.cpp) to check that the ADsPath is syntactically correct for this namespace.
GetObject then determines if the object being requested is a top-level object, a schema object, or some other type of object. If either of the first two, that type of schema class object is created and the appropriate interface pointer retrieved. Otherwise the Sample directory path is created from the ADsPath (for example, "\Seattle\Redmond\AnneA", but in a different directory service it might have had to be "\OU=Seattle\OU=Redmond\CN=AnneA") and control passes to SampleDSOpenObject which opens the object in the example data storage and also retrieves its object type (in this case, "User") (5).
With the information gathered so far, a new object is created (6) to represent the item described by the ADsPath, and a pointer to the IUnknown interface on that object is retrieved. In this case, a generic Active Directory object is created that supports the IUnknown and IADs methods (cgenobj.cpp, core.cpp). The CSampleDSGenObject::AllocateGenObject routine reads the type library information to create the proper dispatch entries for these new objects in order to support IDispatch.
Wrapping this interface pointer into a moniker completes the ResolvePathName (cprov.cpp) function and parsing the display name is done.
All the COM objects created during this process are cached for performance reasons and managed through the binding context. This improves performance for other operations on the same object that immediately follows the moniker binding.
This well-formed Active Directory object is now queried for the interface identifier requested for the initial ADsGetObject call and a pointer to that interface is retrieved (7) and passed back through the ADSI server to the client (8). From then on, the client works directly with the provider component through the interface methods until the initial request is satisfied (9).
Further requests for information about this object from the client usually take the form of requests for property gets and puts, all of which are optimized through the provider's implementation of a property cache (cprops.cpp). Intelligently packing and unpacking data (often including copying and freeing structures and strings) between the native data types on the example provider component's operating system and the Automation VARIANT type supported by ADSI takes place before the properties are loaded into the cache (smpoper.cpp).
The example provider component is designed so that the actual calls to the operating system are logically isolated from the rest of the provider component, creating software that's easily portable to more than one operating system (RegDSAPI.cpp).