void tOleHandler::Close(BOOL fCommit) { /* * We can't use a zero reference count to know when to NULL * this since other things might have AddRef'd the storage. */ //OnInPlaceDeactivate releases this pointer. if (NULL!=m_pIOleIPObject) m_pIOleIPObject->InPlaceDeactivate(); //Close the object saving if necessary if (NULL!=m_pIOleObject) { m_pIOleObject->Close(OLECLOSE_SAVEIFDIRTY); ReleaseInterface(m_pIOleObject); } //Release all other held pointers //CHAPTER24MOD ReleaseInterface(m_pIOleControl); //End CHAPTER24MOD //Release all other held pointers if (NULL!=m_pIViewObject2) { m_pIViewObject2->SetAdvise(m_fe.dwAspect, 0, NULL); ReleaseInterface(m_pIViewObject2); } //We know we only hold one ref from Create or Load ReleaseInterface(m_pObj); return; }
HRESULT CSite::HrFilterIn(LPCTSTR fileName, LPSTREAM* ppFilteredStream, DWORD dwFlags) { HRESULT hr = S_OK; IStream* pInputStream = NULL; ITriEditDocument* pTriEditDoc = NULL; IUnknown* lpUnk = NULL; IUnknown* lpStreamUnk = NULL; lpUnk = GetObjectUnknown(); if (NULL == lpUnk) return E_FAIL; // get ITriEditDoc if (FAILED(hr = lpUnk->QueryInterface(IID_ITriEditDocument, (LPVOID*) &pTriEditDoc))) return hr; if (FAILED(hr = HrFileToStream(fileName, &pInputStream))) goto cleanup; if (FAILED(hr = pTriEditDoc->FilterIn(pInputStream, &lpStreamUnk, dwFlags, NULL))) goto cleanup; if (FAILED(hr = lpStreamUnk->QueryInterface(IID_IStream, (LPVOID*) ppFilteredStream))) goto cleanup; cleanup: ReleaseInterface(pTriEditDoc); ReleaseInterface(lpStreamUnk); ReleaseInterface(pInputStream); return hr; }
VOID CWaveDoc :: Initialize() { ReleaseInterface(m_pDSBuffer); m_pDSBuffer = NULL; m_dwBytesPerSec = NULL; }
VOID CWaveDoc :: SetBuffer(LPDIRECTSOUNDBUFFER pDSBuffer) { ReleaseInterface(m_pDSBuffer); m_pDSBuffer = pDSBuffer; m_pDSBuffer->AddRef(); }
/* * CSite::Close * * Purpose: * Possibly commits the storage, then releases it, afterwards * frees alls the object pointers. * * Parameters: * fCommit BOOL indicating if we're to commit. * * Return Value: * None */ void CSite::Close(BOOL fCommit) { //OnInPlaceDeactivate releases this pointer. if ( NULL != m_pIOleIPObject ) { m_pIOleIPObject->InPlaceDeactivate(); } ReleaseInterface( m_pIOleDocView ); ReleaseInterface( m_pIOleCommandTarget ); ReleaseInterface( m_pObj ); if ( NULL != m_pIOleObject ) { m_pIOleObject->Close( fCommit ? OLECLOSE_SAVEIFDIRTY : OLECLOSE_NOSAVE ); ReleaseInterface( m_pIOleObject ); } }
STDMETHODIMP tOleInPlaceSite::OnInPlaceDeactivate(void) { /* * Since we don't have an Undo command, we can tell the object * right away to discard its Undo state. */ m_pTen->Activate(OLEIVERB_DISCARDUNDOSTATE, NULL); ReleaseInterface(m_pTen->m_pIOleIPObject); return NOERROR; }
COfsDhtmlEditCtrl::~COfsDhtmlEditCtrl() { if(m_pSite!=NULL) { m_pSite->Close(FALSE); ReleaseInterface(m_pSite); m_pSite = NULL; } delete pContextMenu; }
void CAILibraryManager::ReleaseEverything() { T_loadedInterfaces::const_iterator lil; for (lil = loadedAIInterfaceLibraries.begin(); lil != loadedAIInterfaceLibraries.end(); lil++) { CAIInterfaceLibrary* interfaceLib = FetchInterface(lil->first); if ((interfaceLib != NULL) && interfaceLib->IsInitialized()) { interfaceLib->ReleaseAllSkirmishAILibraries(); // only releases the library if its load count is 0 ReleaseInterface(lil->first); } } }
void CAILibraryManager::ReleaseSkirmishAILibrary(const SkirmishAIKey& skirmishAIKey) { CAIInterfaceLibrary* interfaceLib = FetchInterface(skirmishAIKey.GetInterface()); if ((interfaceLib != NULL) && interfaceLib->IsInitialized()) { interfaceLib->ReleaseSkirmishAILibrary(skirmishAIKey); // only releases the library if its load count is 0 ReleaseInterface(skirmishAIKey.GetInterface()); } else { // Not releasing, because the AI Interface is not initialized, // and so neither was the AI. } }
HRESULT CSite::SaveWithFilter(LPCTSTR pchPath) { HRESULT hr = S_OK; if ( pchPath != NULL && *pchPath != 0) { IPersistStreamInit* pPStm = NULL; LPSTREAM pStream = NULL; DWORD dwFlags = 0; // dwFlags = ((CCEditApp*) AfxGetApp())->GetOptions().GetFilterFlags(); // dwFlags |= dwFilterMultiByteStream; hr = m_pObj->QueryInterface( IID_IPersistStreamInit, (void **)&pPStm); if ( SUCCEEDED(hr) ) { hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); ASSERT(SUCCEEDED(hr)); hr = pPStm->Save(pStream, TRUE); ASSERT(SUCCEEDED(hr)); hr = HrFilterOut(pStream, pchPath, dwFlags); ASSERT(SUCCEEDED(hr)); ReleaseInterface(pStream); ReleaseInterface(pPStm); } } return hr; }
CDwnDoc::~CDwnDoc() { Assert(_pDoc == NULL); if(_aryDwnDocInfo.Size()) { OnDocThreadCallback(); } delete[] _ape; delete[] _pbRequestHeaders; ReleaseInterface(_pDownloadNotify); }
HRESULT CSite::HrFilterOutStream(LPSTREAM pSourceStream, LPSTREAM &pOutputStream, DWORD dwFlags) { HRESULT hr = S_OK; // IStream* pOutputStream = NULL; ITriEditDocument* pTriEditDoc = NULL; IUnknown* lpUnk = NULL; IUnknown* lpStreamUnk = NULL; lpUnk = GetObjectUnknown(); if (NULL == lpUnk) return E_FAIL; // get ITriEditDoc if (FAILED(hr = lpUnk->QueryInterface(IID_ITriEditDocument, (LPVOID*) &pTriEditDoc))) return hr; if (FAILED(hr = pTriEditDoc->FilterOut(pSourceStream, &lpStreamUnk, dwFlags, NULL))) goto cleanup; if (FAILED(hr = lpStreamUnk->QueryInterface(IID_IStream, (LPVOID*) &pOutputStream))) goto cleanup; // if (FAILED(hr = HrStreamToFile(pOutputStream, fileName))) // goto cleanup; cleanup: ReleaseInterface(pTriEditDoc); ReleaseInterface(lpStreamUnk); // ReleaseInterface(pOutputStream); return hr; }
FWUtilGlobals::~FWUtilGlobals() { pthread_mutex_destroy(& mDevicesLock) ; cout << "cleaning up global data...\n" ; if (mCommandConstructors) CFRelease(mCommandConstructors) ; if (mCommandNames) CFRelease(mCommandNames) ; if (mDevices) CFRelease(mDevices) ; ReleaseInterface() ; cout << "...done!\n" ; }
//+---------------------------------------------------------------------------- // // Function: InitSurface // // Synopsis: Allocate DirectDraw object which is used to create surfaces // for offscreen rendering // //----------------------------------------------------------------------------- HRESULT InitSurface() { if(g_hrDirectDraw || g_pDirectDraw) // DD already initialized (or failed) { return g_hrDirectDraw; } LOCK_SECTION(g_csOscCache); // Check again after obtaining the lock // (since another thread could have made the attempt while we waited) if(g_hrDirectDraw || g_pDirectDraw) { return g_hrDirectDraw; } IDirectDrawFactory* pDDFactory = NULL; // create the DDFactory used to create the DirectDraw object g_hrDirectDraw = CoCreateInstance(CLSID_DirectDrawFactory, NULL, CLSCTX_INPROC_SERVER, IID_IDirectDrawFactory, (void**)&pDDFactory); if(SUCCEEDED(g_hrDirectDraw)) { // DirectDraw will put up annoying UI if the bpp is less than 8. // Low bpp video cards are simply not support. Force DirectDraw to // silently quietly fail under this circumstance. DWORD dwMode = SetErrorMode(SEM_FAILCRITICALERRORS); // create the actual DirectDraw object from which we can create surfaces later g_hrDirectDraw = pDDFactory->CreateDirectDraw(NULL, GetDesktopWindow(), DDSCL_NORMAL, 0, NULL, &g_pDirectDraw); SetErrorMode(dwMode); // release the factory ReleaseInterface((IUnknown*)pDDFactory); } RRETURN(g_hrDirectDraw); }
HRESULT CSite::Save(LPCTSTR pchPath) { HRESULT hr = S_OK; // OLECHAR szwName[256]; USES_CONVERSION; LPWSTR szwName = T2W(const_cast<LPTSTR>(pchPath)); LPOLESTR pszwName = szwName; LPOLESTR *ppszwName = &pszwName; IPersistFile* pPFile = NULL; hr = m_pObj->QueryInterface( IID_IPersistFile, (void **) &pPFile); if ( SUCCEEDED(hr) && pPFile) { if ( pchPath != NULL && *pchPath != 0) { // MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256); } else { hr = pPFile->GetCurFile(ppszwName); } if ( SUCCEEDED(hr) && ppszwName) { // Call Save on the IPersistFile hr = pPFile->Save(*ppszwName, TRUE); if ( SUCCEEDED(hr) ) { hr = pPFile->SaveCompleted(*ppszwName); } } ReleaseInterface(pPFile); } return hr; }
wxDataObject::~wxDataObject() { ReleaseInterface(m_pIDataObject); }
HRESULT VariantChangeTypeSpecial(VARIANT* pvargDest, VARIANT* pVArg, VARTYPE vt, IServiceProvider* pSrvProvider/*=NULL*/, DWORD dwFlags/*=0*/) { HRESULT hr; IVariantChangeType* pVarChangeType = NULL; if(pSrvProvider) { hr = pSrvProvider->QueryService(SID_VariantConversion, IID_IVariantChangeType, (void**)&pVarChangeType); if(hr) { goto OldWay; } // Use script engine conversion routine. hr = pVarChangeType->ChangeType(pvargDest, pVArg, 0, vt); if(!hr) { goto Cleanup; // ChangeType suceeded we're done... } } // Fall back to our tried & trusted type coercions OldWay: hr = S_OK; if(vt==VT_BSTR && V_VT(pVArg)==VT_NULL) { // Converting a NULL to BSTR V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString(_T("null"), &V_BSTR(pvargDest)); goto Cleanup; } else if(vt==VT_BSTR && V_VT(pVArg)==VT_EMPTY) { // Converting "undefined" to BSTR V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString(_T("undefined"), &V_BSTR(pvargDest)); goto Cleanup; } else if(vt==VT_BOOL && V_VT(pVArg)==VT_BSTR) { // Converting from BSTR to BOOL // To match Navigator compatibility empty strings implies false when // assigned to a boolean type any other string implies true. V_VT(pvargDest) = VT_BOOL; V_BOOL(pvargDest) = FormsStringLen(V_BSTR(pVArg))==0 ? VARIANT_FALSE : VARIANT_TRUE; goto Cleanup; } else if(V_VT(pVArg)==VT_BOOL && vt==VT_BSTR) { // Converting from BOOL to BSTR // To match Nav we either get "true" or "false" V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString( V_BOOL(pVArg)==VARIANT_TRUE?_T("true"):_T("false"), &V_BSTR(pvargDest)); goto Cleanup; } // If we're converting R4 or R8 to a string then we need special handling to // map Nan and +/-Inf. else if(vt==VT_BSTR && (V_VT(pVArg)==VT_R8||V_VT(pVArg)==VT_R4)) { double dblValue = V_VT(pVArg)==VT_R8 ? V_R8(pVArg) : (double)(V_R4(pVArg)); // Infinity or NAN? if(!isFinite(dblValue)) { if(isNAN(dblValue)) { // NAN hr = FormsAllocStringW(_T("NaN"), &(V_BSTR(pvargDest))); } else { // Infinity hr = FormsAllocStringW((dblValue<0)?_T("-Infinity"):_T("Infinity"), &(V_BSTR(pvargDest))); } } else { goto DefaultConvert; } // Any error from allocating string? if(hr) { goto Cleanup; } V_VT(pvargDest) = vt; goto Cleanup; } DefaultConvert: // Default VariantChangeTypeEx. // VARIANT_NOUSEROVERRIDE flag is undocumented flag that tells OLEAUT to convert to the lcid // given. Without it the conversion is done to user localeid hr = VariantChangeTypeEx(pvargDest, pVArg, LCID_SCRIPTING, dwFlags|VARIANT_NOUSEROVERRIDE, vt); if(hr == DISP_E_TYPEMISMATCH) { if(V_VT(pVArg) == VT_NULL) { hr = S_OK; switch(vt) { case VT_BOOL: V_BOOL(pvargDest) = VARIANT_FALSE; V_VT(pvargDest) = VT_BOOL; break; // For NS compatability - NS treats NULL args as 0 default: V_I4(pvargDest)=0; break; } } else if(V_VT(pVArg) == VT_DISPATCH) { // Nav compatability - return the string [object] or null V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString((V_DISPATCH(pVArg))?_T("[object]"):_T("null"), &V_BSTR(pvargDest)); } else if(V_VT(pVArg)==VT_BSTR && (V_BSTR(pVArg) && ((V_BSTR(pVArg))[0]==_T('\0')) ||!V_BSTR(pVArg)) && (vt==VT_I4 || vt==VT_I2 || vt==VT_UI2||vt==VT_UI4 || vt==VT_I8||vt==VT_UI8 || vt==VT_INT || vt==VT_UINT)) { // Converting empty string to integer => Zero hr = S_OK; V_VT(pvargDest) = vt; V_I4(pvargDest) = 0; goto Cleanup; } } else if(hr==DISP_E_OVERFLOW && vt==VT_I4 && (V_VT(pVArg)==VT_R8 || V_VT(pVArg)==VT_R4)) { // Nav compatability - return MAXLONG on overflow V_VT(pvargDest) = VT_I4; V_I4(pvargDest) = MAXLONG; hr = S_OK; goto Cleanup; } // To match Navigator change any scientific notation E to e. if(!hr && (vt==VT_BSTR && (V_VT(pVArg)==VT_R8 || V_VT(pVArg)==VT_R4))) { TCHAR* pENotation; pENotation = _tcschr(V_BSTR(pvargDest), _T('E')); if(pENotation) { *pENotation = _T('e'); } } Cleanup: ReleaseInterface(pVarChangeType); RRETURN(hr); }
wxDropTarget::~wxDropTarget() { ReleaseInterface(m_pIDropTarget); }
/* * 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; }
//+---------------------------------------------------------------------------- // // Member: GetTypeInfoFromCoClass // // Synopsis: Return either the default dispinterface or default source // interface ITypeInfo from a coclass // // Arguments: pTICoClass - ITypeInfo for containing coclass // fSource - Return either source (TRUE) or default (FALSE) interface // ppTI - Location at which to return the interface (may be NULL) // piid - Location at which to return ther interface IID (may be NULL) // // Returns: S_OK, E_xxxx // //----------------------------------------------------------------------------- HRESULT GetTypeInfoFromCoClass(ITypeInfo* pTICoClass, BOOL fSource, ITypeInfo** ppTI, IID* piid) { ITypeInfo* pTI = NULL; TYPEATTR* pTACoClass = NULL; TYPEATTR* pTA = NULL; IID iid; HREFTYPE href; int i; int flags; HRESULT hr; Assert(pTICoClass); if(!ppTI) { ppTI = &pTI; } if(!piid) { piid = &iid; } *ppTI = NULL; *piid = IID_NULL; hr = pTICoClass->GetTypeAttr(&pTACoClass); if(hr) { goto Cleanup; } Assert(pTACoClass->typekind == TKIND_COCLASS); for(i=0; i<pTACoClass->cImplTypes; i++) { hr = pTICoClass->GetImplTypeFlags(i, &flags); if(hr) { goto Cleanup; } if((flags&IMPLTYPEFLAG_FDEFAULT) && ((fSource&&(flags&IMPLTYPEFLAG_FSOURCE)) || (!fSource&&!(flags&IMPLTYPEFLAG_FSOURCE)))) { hr = pTICoClass->GetRefTypeOfImplType(i, &href); if(hr) { goto Cleanup; } hr = pTICoClass->GetRefTypeInfo(href, ppTI); if(hr) { goto Cleanup; } hr = (*ppTI)->GetTypeAttr(&pTA); if(hr) { goto Cleanup; } *piid = pTA->guid; goto Cleanup; } } hr = E_FAIL; Cleanup: if(pTA) { Assert(*ppTI); (*ppTI)->ReleaseTypeAttr(pTA); } ReleaseInterface(pTI); if(pTACoClass) { Assert(pTICoClass); pTICoClass->ReleaseTypeAttr(pTACoClass); } RRETURN(hr); }