C.1 The Binding Sequence

When a client calls the Visual Basic function GetObject() or the Active Directory helper function ADsGetObject(), the actual binding process is as follows:

IBindCtx *pbc;

IMoniker *pmk;

ULONG chEaten;

IUnknown *punk;

IADs *pMyObject;

//

// Create a bind context.

//

CreateBindCtx(0, // reserved

&pbc); // the bind context

//

// Call MkParseDisplayName.

//

MkParseDisplayName(pbc, // the bind context

szPath, // ADsPath, equivalent to a moniker Display Name

&chEaten, // returns number of chars successfully parsed

&pmk); // returns a pointer to a moniker

//

// The moniker returned by MkParseDisplayName points

// to a component object that corresponds to the

// directory service object named by the ADsPath.

//

pmk->BindToObject(pbc, // the moniker

NULL, // the moniker to the left, NULL

IID_IUnknown, // an interface on the object

(void**)&punk); // returns a pointer to the object

//

// QueryInterface for the desired interface. For this

// example, it is IADs.

//

// Note: This step is not necessary if the desired

// interface is requested in the ::BindToObject call.

// However, it is shown here to demonstrate how Visual

// Basic separates the GetObject() call from the Set

// operator. In Visual Basic, the Set operator performs

// a QueryInterface.

//

punk->QueryInterface(IID_IADs, &pMyObject);

//

// Release the bind context and the moniker.

//

pbc->Release();

pmk->Release();

//

// Return the pMyObject interface pointer to the client.

//

Details of CreateBindCtx(), MkParseDisplayName(), and the IMoniker interface can be found in the Win32 SDK. Most of the work happens in the MkParseDisplayName function. Briefly:

1. The MkParseDisplayName parses <NamespacePROGID> from the ADsPath string. Using the PROGID, it creates an instance of the Provider object named Namespace. The Provider object implements IParseDisplayName and is used only for binding Active Directory objects; user programs never explicitly instantiate the Provider object.

2. MkParseDisplayName queries for and obtains an IParseDisplayName interface on the Provider object. It then calls ParseDisplayName(), passing the ADsPath string. The Namespace object is then responsible for resolving the path, creating the correct Active Directory object, wrapping it in a moniker, and returning the moniker to MkParseDisplayName.