次の方法で共有


Adding an IADsExtension Interface Implementation

To compile your ADSI extension and have support for late binding, you need to add the IADsExtension interface implementation to your Visual C++ project. Otherwise, you must type the IADsExtension declaration and implementation.

If you use Visual C++? 6.0 or later, you can use the following procedure to add the IADsExtension interface implementation.

  1. Add IADsExtension to the type library.

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

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

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

    1. Add public IADsExtension as the class declaration.

    2. Add COM_INTERFACE_ENTRY (IADsExtension) in the mapping for COM_MAP.

  2. Add the type information member variable. The type information member variable holds 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 only for example, and may not be completely valid for every situation.

    ADsIIS doesn't support a credentials field, so if the Operate method is passed with ADS_EXT_INITCREDENTIALS, ADsIIS ignores 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 ); 
    }