Adding an IADsExtension Interface Implementation

If you use Visual C++ 6.0 or later, you can use the following procedure to add the IADsExtension interface implementation. Otherwise, you will need to type (or copy and paste) the IADsExtension declaration and implementation.

  1. Add IADsExtension to the type library

    You will need to implement the IADsExtension through the ADs section of the Type Library of your project environment. This will comment out the import .tlb in MyExtension.h, since the activeds.h file is included.

    //#import "c:\winnt\system32\activeds.tlb"
    

    Note   Developers not using Visual C++ 6.0 must also do the following steps:

  2. Add the type information member variable. The type information member variable is used to hold the type information for the IMyExtension interface. Add the following line in the class definition:
    protected:
       ITypeInfo   *m_pTypeInfo;
    
  3. Add the constructor and destructor definitions:
    MyExtension();
    ~MyExtension();
    
  4. Implement the constructor and destructor definitions. You might use something similar to the following code example to make the implementation:
    MyExtension::MyExtension()
    {
      HRESULT hr;
      ITypeLib   *pITypeLib;  
      m_pTypeInfo = NULL;
      hr = LoadRegTypeLib( LIBID_ADSFIRSTEXTLib, 
                         1, 
                         0, 
                         PRIMARYLANGID(GetSystemDefaultLCID()), 
                         &pITypeLib );
    
      if ( SUCCEEDED(hr)
      {
        hr   = pITypeLib->GetTypeInfoOfGuid( IID_IMyExtension, &m_pTypeInfo);
      }
    
      pITypeLib->Release();
    }
    MyExtension::~MyExtension()
    {
         if ( m_pTypeInfo )
        {
            m_pTypeInfo->Release();
        }
        
    }
    
  5. Go to IADsExtension interface implementations in the MyExtension.h file and add the following code. This sample code is intended for example only and may not be completely valid for every situation.

    Note   ADsIIS doesn't support a credentials field, so if the Operate method is passed with ADS_EXT_INITCREDENTIALS, ADsIIS will ignore that flag.

    STDMETHOD(Operate)(ULONG dwCode, VARIANT varData1, VARIANT varData2, VARIANT varData3)
    {
        HRESULT hr = S_OK;
        switch (dwCode) 
        {
        case ADS_EXT_INITCREDENTIALS:
         // At the time of this writing, this case is not 
         // supported by the IIS ADSI provider.
         // MessageBox(NULL, "INITCRED", "ADsExt", MB_OK);
          break;
        default:
          hr = E_FAIL;
          break;
        }        
        return hr;        
    }
    STDMETHOD (PrivateGetIDsOfNames)( 
        REFIID riid,
        OLECHAR __RPC_FAR *__RPC_FAR *rgszNames,
        unsigned int cNames,
        LCID lcid,
        DISPID __RPC_FAR *rgDispid) ;
    {        
          if (rgdispid == NULL)
          {
            return E_POINTER;
          }    
        return  DispGetIDsOfNames(m_pTypeInfo, rgszNames, cNames, rgdispid);
    }
    
    STDMETHOD (PrivateInvoke)( 
        DISPID dispidMember,
        REFIID riid,
        LCID lcid,
        WORD wFlags,
        DISPPARAMS __RPC_FAR *pdispparams,
        VARIANT __RPC_FAR *pvarResult,
        EXCEPINFO __RPC_FAR *pexcepinfo,
        unsigned int __RPC_FAR *puArgErr);
    {
     return DispInvoke( (IMyExtension*)this, 
            m_pTypeInfo,
            dispidMember, 
            wFlags, 
            pdispparams, 
            pvarResult, 
            pexcepinfo, 
            puArgErr );
    }
        


You should now be able to compile and have support for late binding. For the latest information on ADSI, check out the ADSI Web site: http://www.microsoft.com/adsi.