示例#1
0
//*************************************************************
//
// Open the file with anme wzModule and check to see if there is a type 
// with namespace/class of wzNamespace/wzType. If so, return the RegMeta
// corresponding to the file and the mdTypeDef of the typedef
//
//*************************************************************
HRESULT CORPATHService::FindTypeDef(
    __in __in_z LPWSTR wzModule,    // name of the module that we are going to open
    mdTypeRef          tr,          // TypeRef to resolve.
    IMetaModelCommon * pCommon,     // Scope in which the TypeRef is defined.
    REFIID             riid, 
    IUnknown **        ppIScope,
    mdTypeDef *        ptd)         // [OUT] the type that we resolve to
{
    HRESULT                         hr = NOERROR;
    NewHolder<Disp>                 pDisp;
    ReleaseHolder<IMetaDataImport2> pImport = NULL;
    CQuickArray<mdTypeRef>          cqaNesters;
    CQuickArray<LPCUTF8>            cqaNesterNamespaces;
    CQuickArray<LPCUTF8>            cqaNesterNames;
    RegMeta *                       pRegMeta;
    
    _ASSERTE((ppIScope != NULL) && (ptd != NULL));
    
    *ppIScope = NULL;
    
    pDisp = new (nothrow) Disp;
    IfNullGo(pDisp);
    
    IfFailGo(pDisp->OpenScope(wzModule, 0, IID_IMetaDataImport2, (IUnknown **)&pImport));
    pRegMeta = static_cast<RegMeta *>(pImport.GetValue());
    
    // Get the Nesting hierarchy.
    IfFailGo(ImportHelper::GetNesterHierarchy(pCommon, tr, cqaNesters,
                                cqaNesterNamespaces, cqaNesterNames));

    hr = ImportHelper::FindNestedTypeDef(
                                pRegMeta->GetMiniMd(),
                                cqaNesterNamespaces,
                                cqaNesterNames,
                                mdTokenNil,
                                ptd);
    if (SUCCEEDED(hr))
    {
        *ppIScope = pImport.Extract();
    }
    
ErrExit:
    return hr;
} // CORPATHService::FindTypeDef