IDebugComPlusSymbolProvider::GetNameFromTokenIDebugComPlusSymbolProvider::GetNameFromToken

Retourne le nom associé au jeton spécifié son objet de métadonnées spécifié.Returns the name associated with the specified token given its metadata object.

SyntaxeSyntax

HRESULT GetNameFromToken (  
   IUnknown* pMetadataImport,  
   DWORD     dwToken,  
   BSTR*     pbstrName  
);  
int GetNameFromToken (  
   object     pMetadataImport,  
   uint       dwToken,  
   out string pbstrName  
);  

ParamètresParameters

pMetadataImport
[in] Objet qui contient les informations de métadonnées.[in] Object that contains the metadata information.

dwToken
[in] Jeton d’être nommé.[in] Token to be named.

pbstrName
[out] Nom qui correspond au jeton.[out] Name that corresponds to the token.

Valeur de retourReturn Value

En cas de réussite, retourne S_OK; sinon, retourne un code d’erreur.If successful, returns S_OK; otherwise, returns an error code.

ExempleExample

L’exemple suivant montre comment implémenter cette méthode pour un CDebugSymbolProvider objet qui expose la IDebugComPlusSymbolProvider interface.The following example shows how to implement this method for a CDebugSymbolProvider object that exposes the IDebugComPlusSymbolProvider interface.

HRESULT CDebugSymbolProvider::GetNameFromToken(  
    IUnknown* pMetadataImport,  
    DWORD dwToken,  
    BSTR* pbstrName  
)  
{  
    HRESULT hr = S_OK;  
    CComPtr<IMetaDataImport> pMetaData;  

    ASSERT(IsValidObjectPtr(this, CDebugSymbolProvider));  
    ASSERT(IsValidInterfacePtr(pMetadataImport, IUnknown));  

    METHOD_ENTRY(CDebugSymbolProvider::GetNameFromToken);  

    IfFalseGo( pMetadataImport && pbstrName, E_INVALIDARG );  

    *pbstrName = NULL;  
    IfFailGo( pMetadataImport->QueryInterface( IID_IMetaDataImport,  
              (void**) &pMetaData ) );  

    switch ( TypeFromToken(dwToken) )  
    {  
        case mdtModule:  
            IfFailGo( GetModuleName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtTypeDef:  
            IfFailGo( GetTypeName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtFieldDef:  
            IfFailGo( GetFieldName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtMethodDef:  
            IfFailGo( GetMethodName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtEvent:  
            IfFailGo( GetEventName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtProperty:  
            IfFailGo( GetPropertyName( pMetaData, dwToken, pbstrName) );  
            break;  

        case mdtAssembly:  
            IfFailGo( GetAssemblyName( pMetaData, dwToken, pbstrName) );  
            break;  

        default:  
            ASSERT(!"Unsupported token passed to GetNameFromToken");  
            hr = E_FAIL;  
            break;  
    }  

Error:  

    METHOD_EXIT(CDebugSymbolProvider::GetNameFromToken, hr);  
    return hr;  
}  

Voir aussiSee Also

IDebugComPlusSymbolProviderIDebugComPlusSymbolProvider