示例#1
0
void CMFCBindCntrItem::LoadFromMoniker(LPUNKNOWN pUnk, OLECHAR* szwName)
{
	HRESULT hr;
	// Ask the system for a URL Moniker
	IMoniker* pIMoniker;
	hr = CreateURLMoniker(NULL, (LPWSTR)szwName, &pIMoniker);
	if ( SUCCEEDED(hr) )
	{
		// Get the IPersistMoniker interface
		IPersistMoniker* pPMk;
		hr = pUnk->QueryInterface(
								IID_IPersistMoniker,
								(void **)&pPMk);
		if ( SUCCEEDED(hr) )
		{
				// note: do not register our BSC when calling IPM::Load directly
			IBindCtx *pBCtx;
			hr = CreateBindCtx(0, &pBCtx);
			if ( SUCCEEDED(hr) )
			{
				// Call Load on the IPersistMoniker
				hr = pPMk->Load(FALSE, pIMoniker, pBCtx, STGM_READ);
					pBCtx->Release();
			}
			pPMk->Release();
		}
		pIMoniker->Release( );
	}
}
示例#2
0
文件: SITE.CPP 项目: 0anion0/IBN
/*
 * CSite::Load
 *
 * Purpose:
 *  Loads the path provided using IPersistMoniker or IPersistFile. If no path
 *	was provided it simply does an InitNew
 *
 * Parameters:
 *  pchPath - The path
 *
 * Return Value:
 */
HRESULT CSite::Load(LPCTSTR pchPath)
{
    HRESULT   hr = S_OK;

    if ( pchPath != NULL && *pchPath != 0)
    {
        USES_CONVERSION;
        LPWSTR szwName = T2W(const_cast<LPTSTR>(pchPath));

        // Path has been provided so check should we use IPersistMoniker or IPersistFile?
        if (memcmp(pchPath, _T("file:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("http:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("https:"), 5 * sizeof(TCHAR)) == 0)
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);

            // Ask the system for a URL Moniker
            IMoniker* pIMoniker;
            hr = CreateURLMoniker(NULL, (LPWSTR)szwName, &pIMoniker);
            if ( SUCCEEDED(hr) )
            {
                // Get the IPersistMoniker interface
                IPersistMoniker* pPMk;
                hr = m_pObj->QueryInterface(
                         IID_IPersistMoniker,
                         (void **)&pPMk);
                if ( SUCCEEDED(hr) )
                {

                    // note: do not register our BSC when calling IPM::Load directly
                    IBindCtx *pBCtx;
                    hr = CreateBindCtx(0, &pBCtx);
                    if ( SUCCEEDED(hr) )
                    {
                        // Call Load on the IPersistMoniker
                        hr = pPMk->Load(FALSE, pIMoniker, pBCtx, STGM_READ);

                        pBCtx->Release();
                    }
                    ReleaseInterface(pPMk);
                }
                ReleaseInterface( pIMoniker );
            }
        }
        else if ( m_pFR->IsFilterIn() )
        {
            IPersistStreamInit* pPStm = NULL;
            LPSTREAM pFilteredStream = NULL;
            DWORD dwFlags = 0;

//			dwFlags = ((CCEditApp*) AfxGetApp())->GetOptions().GetFilterFlags();
//			dwFlags |= dwFilterMultiByteStream; // loading an ANSI Stream

            hr = m_pObj->QueryInterface(
                     IID_IPersistStreamInit,
                     (void **)&pPStm);

            if ( SUCCEEDED(hr) )
            {
                if (SUCCEEDED(hr = HrFilterIn(pchPath, &pFilteredStream, dwFlags)))
                {
                    hr = pPStm->Load(pFilteredStream);

                    ReleaseInterface(pFilteredStream);
                    ReleaseInterface(pPStm);
                }
            }
        }
        else
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);
            IPersistFile*  pPFile;
            hr = m_pObj->QueryInterface(
                     IID_IPersistFile,
                     (void **) &pPFile);
            if ( SUCCEEDED(hr) )
            {
                // Call Load on the IPersistFile
                hr = pPFile->Load((LPWSTR)szwName, 0);
                ReleaseInterface(pPFile);
            }
        }
    }
    else
    {
        // No path provided so just do an InitNew on the Stream
        IPersistStreamInit* pPStm;
        hr = m_pObj->QueryInterface(
                 IID_IPersistStreamInit,
                 (void **)&pPStm);
        if ( SUCCEEDED(hr) )
        {
            hr = pPStm->InitNew();
            ReleaseInterface(pPStm);
        }
    }

    return hr;
}