当前位置: 首页>>代码示例>>C++>>正文


C++ CFile::ImportFile方法代码示例

本文整理汇总了C++中CFile::ImportFile方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::ImportFile方法的具体用法?C++ CFile::ImportFile怎么用?C++ CFile::ImportFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFile的用法示例。


在下文中一共展示了CFile::ImportFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddImport

HRESULT CAsmLink::AddImport(mdAssembly AssemblyID, mdToken ImportToken, DWORD dwFlags, mdFile * pFileToken)
{
    // If we have already emitted the manifest, and then we import
    // a file with a CA that maps to an assembly option, we're in trouble!
    ASSERT(m_bInited && !m_bPreClosed && !m_bManifestEmitted);

    HRESULT hr;
    CFile *file = NULL;
    if (TypeFromToken(ImportToken) == mdtModule) {
        ASSERT(RidFromToken(ImportToken) < m_pModules->CountFiles());
        hr = m_pModules->GetFile( ImportToken, &file);
    } else {
        ASSERT(TypeFromToken(ImportToken) == mdtAssemblyRef && RidFromToken(ImportToken) < m_pImports->CountFiles());
        hr = m_pImports->GetFile( ImportToken, &file);
    }
    if (FAILED(hr))
        return hr;
    ASSERT(file != NULL);
    if (FAILED(hr = m_pAssem->AddFile(file, dwFlags, pFileToken)))
        return hr;
    else if (AssemblyID == AssemblyIsUBM) {
        if (pFileToken)
            *pFileToken = ImportToken;
        return S_FALSE;
    }
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1));
    if (FAILED(hr = m_pModules->RemoveFile( ImportToken)))
        return hr;
    if (FAILED(hr = file->ImportFile( NULL, m_pAssem)))
        return hr;
    return file->ImportResources(m_pAssem);
}
开发者ID:ArildF,项目名称:masters,代码行数:32,代码来源:asmlink.cpp

示例2: FileNameTooLong

HRESULT CAsmLink::ImportFile2(LPCWSTR pszFilename, LPCWSTR pszTargetName, IMetaDataAssemblyImport *pAssemblyScopeIn, 
                      BOOL fSmartImport, mdToken *pFileToken, IMetaDataAssemblyImport **ppAssemblyScope, 
                      DWORD *pdwCountOfScopes)
{
    ASSERT(m_bInited);
    LPWSTR newTarget = NULL;
    bool bNewTarget = false;

    IMetaDataAssemblyImport *pAImport = NULL;
    IMetaDataImport *pImport = NULL;
    mdAssembly tkAssembly;
    if (pszFilename && wcslen(pszFilename) > MAX_PATH)
        return FileNameTooLong(pszFilename);
    if (pszTargetName && wcslen(pszTargetName) > MAX_PATH)
        return FileNameTooLong(pszTargetName); // File name too long

    if (pszTargetName == NULL)
        newTarget = VSAllocStr(pszFilename);
    else
        newTarget = VSAllocStr(pszTargetName);
    
    if (_wcsicmp(newTarget, pszFilename) == 0) {
    } else {
        bNewTarget = true;
    }

    if ((pAImport = pAssemblyScopeIn) != NULL)
    {
        pAImport->AddRef();
    }
    else
    {
        HRESULT hr = m_pDisp->OpenScope(pszFilename, ofRead | ofNoTypeLib, IID_IMetaDataAssemblyImport, (IUnknown**)&pAImport);
        if (FAILED(hr)) {
            *pFileToken = 0;
            if (ppAssemblyScope) *ppAssemblyScope = NULL;
            if (pdwCountOfScopes) *pdwCountOfScopes = 0;
            VSFree(newTarget);
            return hr;
        }
    }

    HRESULT hr;
    VERIFY(SUCCEEDED(hr = pAImport->QueryInterface( IID_IMetaDataImport, (void**)&pImport)));
    hr = pAImport->GetAssemblyFromScope( &tkAssembly);

    if (FAILED(hr)) {
        hr = S_FALSE;
        // This is NOT an assembly
        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        if (pdwCountOfScopes) *pdwCountOfScopes = 1;
        *pFileToken = mdTokenNil;
        CFile* file = new CFile(newTarget, pImport, m_pError, this);
        if (bNewTarget) {
            if (SUCCEEDED(hr = file->SetSource(pszFilename)))
                hr = file->UpdateModuleName();
        }
        pAImport->Release();
        pImport->Release();
        if (SUCCEEDED(hr) && SUCCEEDED(hr = m_pModules->AddFile( file, 0, pFileToken))) {
            if (fSmartImport)
                hr = file->ImportFile( NULL, NULL);
            *pFileToken = TokenFromRid(RidFromToken(*pFileToken), mdtModule);
        }
        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        if (pdwCountOfScopes) *pdwCountOfScopes = 1;
        VSFree(newTarget);
        return hr == S_OK ? S_FALSE : hr;
    } else {
        // It is an Assembly
        CAssemblyFile* assembly = new CAssemblyFile( pszFilename, pAImport, pImport, m_pError, this);
        if (ppAssemblyScope)
            *ppAssemblyScope = pAImport;
        else
            pAImport->Release();
        pImport->Release();
        if (m_bDontDoHashes)
            assembly->DontDoHash();
        hr = assembly->ImportAssembly(pdwCountOfScopes, fSmartImport, m_pDisp);

        if (SUCCEEDED(hr) && bNewTarget)
            hr = assembly->ReportError( ERR_CantRenameAssembly, mdTokenNil, NULL, pszFilename);

        if (FAILED(hr)) {
            delete assembly;
            VSFree(newTarget);
            return hr;
        }

        VSFree(newTarget);
        if (FAILED(hr = m_pImports->AddFile( assembly, 0, pFileToken)))
            delete assembly;
        return SUCCEEDED(hr) ? S_OK : hr;
    }
}
开发者ID:ArildF,项目名称:masters,代码行数:95,代码来源:asmlink.cpp


注:本文中的CFile::ImportFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。