Ejemplo n.º 1
0
HRESULT CAsmLink::LinkResource(mdAssembly AssemblyID, LPCWSTR pszFileName, LPCWSTR pszNewLocation, LPCWSTR pszResourceName, DWORD dwFlags)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);

    if (wcslen(pszFileName) > MAX_PATH)
        return FileNameTooLong(pszFileName); // File name too long
    HRESULT hr = S_OK;
    if (AssemblyID == AssemblyIsUBM) {
        hr = E_INVALIDARG;
    } else {
        if (pszNewLocation == NULL || pszNewLocation[0] == 0)
            pszNewLocation = pszFileName;
        
        CFile *file = NULL;
        file = new CFile( pszNewLocation, (IMetaDataEmit*)NULL, m_pError, this);
        if (file != NULL && pszNewLocation != NULL && pszNewLocation[0] != 0 &&
            wcscmp(pszFileName, pszNewLocation) != 0) {
            if (FAILED(hr = file->SetSource(pszFileName))) {
                delete file;
                return hr;
            }
        }
        hr = m_pAssem->AddFile( file, ffContainsNoMetaData, NULL);
        if (SUCCEEDED(hr))
            hr = m_pAssem->AddResource(file->GetFileToken(), pszResourceName, 0, dwFlags);
        else
            delete file;
    }
    return hr;
}
Ejemplo n.º 2
0
HRESULT CAsmLink::ExportType(mdAssembly AssemblyID, mdToken FileToken, mdTypeDef TypeToken,
                      LPCWSTR pszTypename, DWORD dwFlags, mdExportedType* pType)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT(AssemblyID == FileToken || (RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile));
    if (AssemblyID == AssemblyIsUBM || FileToken == AssemblyID)
        return S_FALSE;

    HRESULT hr;
    CFile *file = NULL;

    if (FAILED(hr = m_pAssem->GetFile(RidFromToken(FileToken), &file)))
        return hr;

    return m_pAssem->AddExportType( file->GetFileToken(), TypeToken, pszTypename, dwFlags, pType);
}
Ejemplo n.º 3
0
HRESULT CAsmLink::EmbedResource(mdAssembly AssemblyID, mdToken FileToken, LPCWSTR pszResourceName, DWORD dwOffset, DWORD dwFlags)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile) ||
        (FileToken == AssemblyID));

    HRESULT hr = S_OK;
    CFile *file = NULL;
    if (AssemblyID == AssemblyIsUBM) {
        if (SUCCEEDED(hr = m_pAssem->GetFile(FileToken, &file)))
            hr = file->AddResource(mdTokenNil, pszResourceName, dwOffset, dwFlags);
    } else if (FileToken == AssemblyID) {
        hr = m_pAssem->AddResource(mdTokenNil, pszResourceName, dwOffset, dwFlags);
    } else {
        if (SUCCEEDED(hr = m_pAssem->GetFile(FileToken, &file)))
            hr = m_pAssem->AddResource(file->GetFileToken(), pszResourceName, dwOffset, dwFlags);
    }
    return hr;
}