⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basehand.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {
	IHXComponentPlugin* pIComp = NULL;
	if( SUCCEEDED( pIUnkPlugin->QueryInterface( IID_IHXComponentPlugin, (void**) &pIComp ) ) )
	{
	    // Ask for the correct object by CLSID
	    IHXBuffer* pCLSID = NULL;
	    if( SUCCEEDED( m_pValues->GetPropertyBuffer( PLUGIN_COMPONENT_CLSID, pCLSID ) ) )
	    {
		if( FAILED( pIComp->CreateComponentInstance( *(GUID*) pCLSID->GetBuffer(), pUnknown, pIUnkOuter ) ) )
		{
		    retVal = CREATE_INSTANCHXR_FAILURE;
		}
		HX_RELEASE( pCLSID );
	    }
	    else
	    {
		// Hmmm...we have a component plugin without a CLSID.  Serious internal error
		retVal = BAD_PLUGIN;
	    }

	    // Release the interface, and destroy the plugin
	    HX_RELEASE( pIComp );
	    HX_RELEASE( pIUnkPlugin );
	}
	else
	{
	    // If this isn't a component plugin, then we can't aggregate anything
	    if( pIUnkOuter )
	    {
		HX_RELEASE( pIUnkPlugin );
		retVal = AGGREGATION_NOT_SUPPORTED;
	    }
	    else
	    {
		pUnknown = pIUnkPlugin;
	    }
	}
    }

    return retVal;
}

BOOL	BaseHandler::Plugin::IsLoaded()
{
    if (!m_pPluginDLL)
	return FALSE;

    return m_pPluginDLL->IsLoaded();
}

HX_RESULT BaseHandler::Plugin::GetPluginInfo(REF(IHXValues*) pVals)
{
    if (m_pValues)
    {
	pVals = m_pValues;
	return HXR_OK;
    }
    pVals = NULL;
    return HXR_FAIL;
}

IHXBuffer* BaseHandler::Plugin::GetFileName()
{
    IHXBuffer* retVal = NULL;

    // Get the filename from m_pValues.  We can't get it from the DLL,
    // because we may be in the process of loading, and we just got it
    // from the preferences
    if( m_pValues )
    {
	m_pValues->GetPropertyCString( PLUGIN_FILENAME, retVal );
    }

    return retVal;
}

BaseHandler::Errors
BaseHandler::Plugin::GetBasicValues(IHXPlugin* pHXPlugin)
{
    return NO_ERRORS;

    const char*	pszDescription = NULL;
    const char* pszCopyright = NULL;
    const char* pszMoreInfoUrl = NULL;
    ULONG32	ulVersionNumber = 0;
    BOOL	nload_multiple = 0;

    if (HXR_OK != pHXPlugin->GetPluginInfo(nload_multiple, pszDescription,
				       pszCopyright, pszMoreInfoUrl, ulVersionNumber))
    {
        return BAD_PLUGIN;
    }

    IHXBuffer* pBuffer = NULL;
    m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
    if (pszDescription)
    {
	pBuffer->Set((UCHAR*)pszDescription, strlen(pszDescription)+1);
    }
    m_pValues->SetPropertyCString(PLUGIN_DESCRIPTION2, pBuffer);
    pBuffer->Release();
    m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
    if (pszCopyright)
    {
	pBuffer->Set((UCHAR*)pszCopyright, strlen(pszCopyright)+1);
    }
    m_pValues->SetPropertyCString(PLUGIN_COPYRIGHT2, pBuffer);
    pBuffer->Release();
    m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
    if (pszMoreInfoUrl)
    {
	pBuffer->Set((UCHAR*)pszMoreInfoUrl, strlen(pszMoreInfoUrl)+1);
    }
    m_pValues->SetPropertyCString(PLUGIN_COPYRIGHT, pBuffer);
    pBuffer->Release();

    m_pValues->SetPropertyULONG32(PLUGIN_LOADMULTIPLE, nload_multiple);
    m_pValues->SetPropertyULONG32(PLUGIN_VERSION, ulVersionNumber);
    return NO_ERRORS;
}


BaseHandler::Errors
BaseHandler::Plugin::GetExtendedValues(IHXPlugin* pHXPlugin)
{
//    Errors				result		    = NO_ERRORS;
    IHXFileFormatObject*		pFileFormat	    = NULL;
//    IHXMetaFileFormatObject*		pMetaFileFormat	    = NULL;
    IHXFileWriter*			pFileWriter	    = NULL;
    IHXBroadcastFormatObject*		pBroadcastFormat    = NULL;
    IHXFileSystemObject*		pFileSystem	    = NULL;
    IHXRenderer*			pRenderer	    = NULL;
    IHXDataRevert*			pDataRevert	    = NULL;
    IHXStreamDescription*		pStreamDescription  = NULL;
    IHXPlayerConnectionAdviseSink*	pAllowanceFormat    = NULL;
    IHXCommonClassFactory*		pClassFactory       = NULL;
    IHXPluginProperties*		pIHXPluginPropertiesThis = NULL;
    UINT32				nCountInterfaces    = 0;


    // file system
    if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXFileSystemObject, (void**) &pFileSystem))
    {
	const char* pszShortName;
	const char* pszProtocol;

	if (HXR_OK != pFileSystem->GetFileSystemInfo(pszShortName, pszProtocol))
	{
	    HX_RELEASE (pFileSystem);
	    return  CANT_GET_RENDERER_INFO; //XXXAH Cleanup?
	}

	SetPluginProperty(PLUGIN_FILESYSTEM_TYPE);

	IHXBuffer* pBuffer = NULL;
	m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
	if (pszShortName)
	{
	    pBuffer->Set((UCHAR*)pszShortName, strlen(pszShortName)+1);
	}
	m_pValues->SetPropertyCString(PLUGIN_FILESYSTEMSHORT, pBuffer);
	pBuffer->Release();
	m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
	if (pszProtocol)
	{
	    pBuffer->Set((UCHAR*)pszProtocol, strlen(pszProtocol)+1);
	}
	m_pValues->SetPropertyCString(PLUGIN_FILESYSTEMPROTOCOL, pBuffer);
	pBuffer->Release();

	pFileSystem->Release();
	nCountInterfaces++;
    }

    // file format
    if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXFileFormatObject, (void**)&pFileFormat) ||
	HXR_OK == pHXPlugin->QueryInterface(IID_IHXMetaFileFormatObject, (void**)&pFileFormat) ||
	HXR_OK == pHXPlugin->QueryInterface(IID_IHXFileWriter, (void**)&pFileWriter))
    {
	// fine we are in now we will get the correct type.
	if (pFileFormat)
	{
	    pFileFormat->Release();
	}
	else
	{
	    pFileWriter->Release();
	}

	IHXMetaFileFormatObject* pMetaFileFormat;

	const char**		ppszMimeTypes = NULL;
	const char**		ppszExtensions = NULL;
	const char**		ppszOpenNames = NULL;

	if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXFileFormatObject, (void**)&pFileFormat))
	{
	    pFileFormat->GetFileFormatInfo( ppszMimeTypes,
					    ppszExtensions,
					    ppszOpenNames);
	    pFileFormat->Release();
	    SetPluginProperty(PLUGIN_FILEFORMAT_TYPE);
	}

	if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXMetaFileFormatObject, (void**)&pMetaFileFormat))
	{
	    pMetaFileFormat->GetMetaFileFormatInfo( ppszMimeTypes,
						    ppszExtensions,
						    ppszOpenNames);
	    pMetaFileFormat->Release();

	    SetPluginProperty(PLUGIN_METAFILEFORMAT_TYPE);
	}

	if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXFileWriter, (void**)&pFileWriter))
	{
	    pFileWriter->GetFileFormatInfo( ppszMimeTypes,
					    ppszExtensions,
					    ppszOpenNames);
	    pFileWriter->Release();

	    SetPluginProperty(PLUGIN_FILEWRITER_TYPE);
	}

	IHXBuffer* pBuffer = NULL;
	if (ppszMimeTypes)
	{
	    CatStrings((char**)ppszMimeTypes, pBuffer);	    //XXXAH this had better be const in reality!
	    m_pValues->SetPropertyCString(PLUGIN_FILEMIMETYPES, pBuffer);
	    pBuffer->Release();
	}

	if (ppszExtensions)
	{
	    CatStrings((char**)ppszExtensions, pBuffer);		//XXXAH this had better be const in reality!
	    m_pValues->SetPropertyCString(PLUGIN_FILEEXTENSIONS, pBuffer);
	    pBuffer->Release();
	}

	if (ppszOpenNames)
	{
	    CatStrings((char**)ppszOpenNames, pBuffer);		//XXXAH this had better be const in reality!
	    m_pValues->SetPropertyCString(PLUGIN_FILEOPENNAMES, pBuffer);
	    pBuffer->Release();
	}
	nCountInterfaces++;
    }

    // renderer
    if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXRenderer, (void**)&pRenderer))
    {
	char**	ppszMimeTypes;
        UINT32	initial_granularity = 0;

	// get the basic info
	if (HXR_OK == pRenderer->GetRendererInfo((const char**&)ppszMimeTypes, initial_granularity))
	{
	    IHXBuffer* pBuffer;
	    if (ppszMimeTypes)
	    {
		CatStrings(ppszMimeTypes, pBuffer);
	    }
	    m_pValues->SetPropertyCString(PLUGIN_RENDERER_MIME, pBuffer);
	    pBuffer->Release();
	    m_pValues->SetPropertyULONG32(PLUGIN_RENDERER_GRANULARITY, initial_granularity);
	    SetPluginProperty(PLUGIN_RENDERER_TYPE);
	}

	HX_RELEASE(pRenderer);
	nCountInterfaces++;
    }

    // stream description
    if (HXR_OK == pHXPlugin->QueryInterface(IID_IHXStreamDescription, (void**)&pStreamDescription))
    {
	const char* pszMimeType;
	IHXBuffer* pBuffer;
	if (HXR_OK != pStreamDescription->GetStreamDescriptionInfo(pszMimeType))
	{
	    HX_RELEASE (pStreamDescription);
	    return CANT_GET_FILE_FORMAT_INFO;	// XXXAH Cleanup?
	}
	pStreamDescription->Release();
	m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
	if (pszMimeType)
	{
	    pBuffer->Set((UCHAR*)pszMimeType, strlen(pszMimeType)+1);
	}
	m_pValues->SetPropertyCString(PLUGIN_STREAMDESCRIPTION, pBuffer);
	pBuffer->Release();

	SetPluginProperty(PLUGIN_STREAM_DESC_TYPE);
	nCountInterfaces++;
    }

    // common class factory
    if(HXR_OK == pHXPlugin->QueryInterface(IID_IHXCommonClassFactory,
					(void**)&pClassFactory))
    {
	SetPluginProperty(PLUGIN_CLASS_FACTORY_TYPE);
	HX_RELEASE (pClassFactory);
	nCountInterfaces++;
    }

    // NO MORE NEW PLUGIN INFORMATION INTERFACES!!!!
    //
    // THIS IS THE LAST ONE!!!!!
    if( SUCCEEDED( pHXPlugin->QueryInterface( IID_IHXPluginProperties, (void**)&pIHXPluginPropertiesThis ) ) )
    {
	IHXValues* pIHXValuesProperties = NULL;

	pHXPlugin->InitPlugin(m_pContext);

	if( SUCCEEDED( pIHXPluginPropertiesThis->GetProperties( pIHXValuesProperties ) ) && pIHXValuesProperties )
	{
	    CHXHeader::mergeHeaders( m_pValues, pIHXValuesProperties );
	}

	HX_RELEASE(pIHXValuesProperties);

	// XXXkshoop Let this coincide with other interfaces.. for now..
	//nCountInterfaces++;
    }

    HX_RELEASE(pIHXPluginPropertiesThis);

    HX_ASSERT(nCountInterfaces<2);
    return NO_ERRORS;
}

void BaseHandler::Plugin::InitializeComponentPlugin( IHXPlugin* pIPlugin, IHXValues* pIValues )
{
    // Setup basic data
    // XXXHP - this is unnecessary information as it is stored on a PER COMPONENT not PER PLUGIN basis in this case.
    // GetBasicValues( pIPlugin );

    // Copy data from pIValues
    CHXHeader::mergeHeaders( m_pValues, pIValues );
}

HX_RESULT BaseHandler::Plugin::CatStrings(char** pInStrings,
				    REF(IHXBuffer*) pOutBuffer)
{
    ULONG32 nAllocedSpace   = 100;
    char*   ptemp	    = new char[nAllocedSpace];
    char*   ptemp2	    = NULL;
    ULONG32 nStrLen	    = 0;
    ULONG32 nNewStrLen	    = 0;

    *ptemp	= 0;
    pOutBuffer	= 0;

    for(; *pInStrings; pInStrings++)
    {
	nNewStrLen = strlen(*pInStrings);
	if (nNewStrLen+ nStrLen >= nAllocedSpace)
	{
	    // double if the new string is less than the new space
	    // or add double what it required.
	    if (nNewStrLen< nAllocedSpace)
	    {
		nAllocedSpace*=2;
	    }
	    else
	    {
		nAllocedSpace+=nNewStrLen*2;
	    }

	    ptemp2 = new char[nAllocedSpace];
	    memcpy(ptemp2, ptemp, nStrLen+1); /* Flawfinder: ignore */
	    delete [] ptemp;
	    ptemp = ptemp2;
	}
	// XXXAH I must trim the strings before I add them to this string.
	// the find function DEPENDS UPON THIS.
	SafeStrCat(ptemp,  *pInStrings, nAllocedSpace);
	if (*(pInStrings+1))
	{
	    SafeStrCat(ptemp,  BaseHandler::zm_pszValueSeperator, nAllocedSpace);	// XXXAH Perhaps a define?
	}
	nStrLen+=nNewStrLen+1;
    }
    m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pOutBuffer);
    pOutBuffer->Set((UCHAR*)ptemp, strlen(ptemp)+1);
    delete[] ptemp;
    return HXR_OK;
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      BaseHandler::Plugin::QueryInterface
//  Purpose:
//      Implement this to export the interfaces supported by your
//      object.
//
STDMETHODIMP
BaseHandler::Plugin::QueryInterface(REFIID riid, void** ppvObj)
{
    if (IsEqualIID(riid, IID_IUnknown))
    {
        AddRef();
        *ppvObj = (IUnknown*)this;
        return HXR_OK;
    }

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      BaseHandler::Plugin::AddRef
//  Purpose:
//      Everyone usually implements this the same... feel free to use
//      this implementation.
//
STDMETHODIMP_(ULONG32)
BaseHandler::Plugin::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      BaseHandler::Plugin::Release
//  Purpose:
//      Everyone usually implements this the same... feel free to use
//      this implementation.
//
STDMETHODIMP_(ULONG32)
BaseHandler::Plugin::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}


/**********************************************************************************
***		    BaseHandler::PluginDLL					***
***********************************************************************************/

BaseHandler::PluginDLL::PluginDLL( const char* pszFileName, PluginMountPoint* pMountPoint,
					BaseHandler* pBaseHandler )
    : m_fpCreateInstance(NULL)
    , m_fpShutdown(NULL)
    , m_fCanUnload(NULL)
    , m_pMountPoint( pMountPoint )
    , m_pFileName( NULL )
    , m_pNamespace( NULL )
    , m_nSizeBites(0)
    , m_lRefCount(0)
    , m_NumOfPlugins(0)
    , m_pDLLAccess(NULL)
    , m_bHas_factory(FALSE)
    , m_bLoaded(FALSE)
    , m_nActiveReferences(0)
    , m_pBaseHandler(pBaseHandler)
    , m_bDoesExist(TRUE)
{
    // Always create an IHXBuffer and store the filename there
    CHXBuffer* pCHXBuffer = new CHXBuffer();
    if( SUCCEEDED( pCHXBuffer->QueryInterface( IID_IHXBuffer,(void**) &m_pFileName ) ) )
    {
	if (pszFileName)
	{
	    // Make sure there are no path components in the filename
	    HX_ASSERT( !strrchr( pszFileName, BaseHandler::zm_cDirectorySeperator ) );

	    m_pFileName->Set( (BYTE*) pszFileName, ::strlen( pszFileName ) + 1 );
	}
    }

    m_pDLLAccess = new DLLAccess();
}


BaseHandler::PluginDLL::~PluginDLL()
{
    HX_RELEASE( m_pFileName );
    HX_RELEASE( m_pNamespace );

    if (m_pDLLAccess)
    {
        if (m_bLoaded)
	{
	    if (m_fpShutdown)
	    {
		m_fpShutdown();
		m_fpShutdown = NULL;
	    }

	    m_pDLLAccess->close();
	}

	delete m_pDLLAccess;
	m_pDLLAccess = 0;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -