MeaGUID& MeaGUID::Assign(LPCTSTR guidStr) { if (guidStr == NULL) { AfxThrowOleException(E_POINTER); } if (_tcslen(guidStr) != 36) { AfxThrowOleException(E_INVALIDARG); } int field[11]; int count = _stscanf_s(guidStr, _T("%08lx-%04hx-%04hx-%02hx%02hx-%02hx%02hx%02hx%02hx%02hx%02hx"), &field[0], &field[1], &field[2], &field[3], &field[4], &field[5], &field[6], &field[7], &field[8], &field[9], &field[10]); if (count != 11) { AfxThrowOleException(E_INVALIDARG); } m_guid.Data1 = static_cast<DWORD>(field[0]); m_guid.Data2 = static_cast<WORD>(field[1]); m_guid.Data3 = static_cast<WORD>(field[2]); for (int i = 0; i < 8; i++) { m_guid.Data4[i] = static_cast<BYTE>(field[i+3]); } return *this; }
/////////////////////////////////////////////////////////////////////// //功能:重设对应ole属面窗口的大小 /////////////////////////////////////////////////////////////////////// void COlePropPage::ResetPropRect(RECT *pRect) { HRESULT hRes = E_FAIL; try { CRect pgrect; GetWindowRect(&pgrect); ScreenToClient(pgrect); hRes = m_pPropPage->Activate( GetSafeHwnd(), pgrect, TRUE ); if( FAILED( hRes ) ) AfxThrowOleException( hRes ); hRes = m_pPropPage->Show( SW_SHOW ); if( FAILED( hRes ) ) AfxThrowOleException( hRes ); } catch (COleException * e) { throw (e); } // Add WS_EX_CONTROLPARENT style to property page // necessary to allow tabbing from page to sheet. // Get COM Prop Page CWnd * pWnd = GetWindow(GW_CHILD); CString str; ::GetClassName(pWnd->GetSafeHwnd(), str.GetBuffer(128), 128); str.ReleaseBuffer(); if (str == (CString)_T("#32770")) pWnd->ModifyStyleEx(0,WS_EX_CONTROLPARENT,0); }
BOOL COleServerItem::GetLinkSourceData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); LPOLEOBJECT lpOleObject = GetOleObject(); ASSERT(lpOleObject != NULL); // get moniker from ole object LPMONIKER lpMoniker; SCODE sc = lpOleObject->GetMoniker(OLEGETMONIKER_TEMPFORUSER, OLEWHICHMK_OBJFULL, &lpMoniker); if (sc != S_OK) { TRACE0("Warning: unable to get moniker for object.\n"); return FALSE; } ASSERT(lpMoniker != NULL); // create a memory based stream to write the moniker to LPSTREAM lpStream; if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK) { lpMoniker->Release(); AfxThrowMemoryException(); } ASSERT(lpStream != NULL); // write the moniker to the stream, and add it to the clipboard sc = ::OleSaveToStream(lpMoniker, lpStream); lpMoniker->Release(); if (sc != S_OK) { lpStream->Release(); AfxThrowOleException(sc); } // write the class ID of the document to the stream as well COleLinkingDoc* pDoc = GetDocument(); ASSERT(pDoc->m_pFactory != NULL); sc = WriteClassStm(lpStream, pDoc->m_pFactory->GetClassID()); if (sc != S_OK) { lpStream->Release(); AfxThrowOleException(sc); } // setup the STGMEDIUM lpStgMedium->tymed = TYMED_ISTREAM; lpStgMedium->pstm = lpStream; lpStgMedium->pUnkForRelease = NULL; return TRUE; }
void COleServerItem::GetEmbedSourceData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); LPLOCKBYTES lpLockBytes; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); LPSTORAGE lpStorage; sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); AfxThrowOleException(sc); } ASSERT(lpStorage != NULL); // setup for save copy as COleServerDoc* pDoc = GetDocument(); pDoc->m_bSameAsLoad = FALSE; pDoc->m_bRemember = FALSE; TRY { OnSaveEmbedding(lpStorage); pDoc->CommitItems(FALSE); } CATCH_ALL(e) { // release storage and lock bytes VERIFY(lpStorage->Release() == 0); VERIFY(lpLockBytes->Release() == 0); pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; THROW_LAST(); } END_CATCH_ALL pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; lpLockBytes->Release(); // add it to the data source lpStgMedium->tymed = TYMED_ISTORAGE; lpStgMedium->pstg = lpStorage; lpStgMedium->pUnkForRelease = NULL; }
MeaGUID::MeaGUID() { HRESULT hr = CoCreateGuid(&m_guid); if (FAILED(hr)) { AfxThrowOleException(hr); } }
void CBoxHttpHost::put_Application(VARIANT& varKey, VARIANT& var) { if(varKey.vt == VT_ERROR || var.vt == VT_ERROR) AfxThrowOleException(TYPE_E_TYPEMISMATCH); m_pApplication->put_Item(varKey, var); }
void COleClientItem::CheckGeneral(SCODE sc) // set 'm_scLast' // throw exception if not ok to continue { ASSERT_VALID(this); m_scLast = S_OK; // assume things are ok // then, check for error if (sc != S_OK) { m_scLast = sc; if (!FAILED(sc)) { #ifdef _DEBUG // warn about non-NULL success codes TRACE1("Warning: operation returned scode = %s.\n", AfxGetFullScodeString(m_scLast)); #endif return; } // this error wasn't expected, so throw an exception AfxThrowOleException(sc); } }
VARIANT CBoxEncoding::StrToBin(VARIANT& var, VARIANT &varCP) { CBoxBinPtr varString(var, VT_BSTR); UINT nCodePage; if(varCP.vt == VT_ERROR) nCodePage = _AtlGetConversionACP(); else { CComVariant varTemp; varTemp.ChangeType(VT_I4, &varCP); if(varTemp.vt == VT_I4) nCodePage = varTemp.lVal; else AfxThrowOleException(TYPE_E_TYPEMISMATCH); } int _nTempCount = ::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, NULL, 0, NULL, NULL); CBoxBinPtr varPtr(_nTempCount); ::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, varPtr, _nTempCount, NULL, NULL); return varPtr; }
long CStringCollect::Remove(const VARIANT FAR& removeValue) { int nIndex = -1; VARIANT varTemp; VariantInit(&varTemp); const VARIANT* pvar = &removeValue; if (removeValue.vt != VT_BSTR) { if (VariantChangeType(&varTemp, (VARIANT*)&removeValue, 0, VT_I4) == NOERROR) pvar = &varTemp; else if (VariantChangeType(&varTemp, (VARIANT*)&removeValue, 0, VT_BSTR) == NOERROR) pvar = &varTemp; else AfxThrowOleException(DISP_E_TYPEMISMATCH); } if (pvar->vt == VT_BSTR) nIndex = (int)Find(CString(pvar->bstrVal)); else if (pvar->vt == VT_I4) nIndex = (int)pvar->lVal; VariantClear(&varTemp); CheckIndex(nIndex); m_strArray.RemoveAt(nIndex); return (long)m_strArray.GetSize(); }
STDMETHODIMP COleUILinkInfo::UpdateLink( DWORD dwLink, BOOL /*fErrorMessage*/, BOOL /*fErrorAction*/) { COleClientItem* pItem = (COleClientItem*)dwLink; ASSERT_VALID(pItem); ASSERT_KINDOF(COleClientItem, pItem); SCODE sc; TRY { // link not up-to-date, attempt to update it if (!pItem->UpdateLink()) AfxThrowOleException(pItem->GetLastStatus()); pItem->m_bLinkUnavail = FALSE; sc = S_OK; } CATCH_ALL(e) { pItem->m_bLinkUnavail = TRUE; sc = COleException::Process(e); pItem->ReportError(sc); DELETE_EXCEPTION(e); } END_CATCH_ALL return sc; }
BOOL COleServerItem::OnInitFromData( COleDataObject* /*pDataObject*/, BOOL /*bCreation*/) { ASSERT_VALID(this); AfxThrowOleException(E_NOTIMPL); return FALSE; }
COlePropPage::COlePropPage(CLSID clsidPage, LPUNKNOWN* lpAryUnk, int& count) : CPropertyPage(COlePropPage::IDD), m_clsidPage(clsidPage), m_pObject(lpAryUnk) { // Create COM Property page and get IPropertyPage interface EnableAutomation(); HRESULT hRes = E_FAIL; m_pPropPage=NULL; try { hRes = CoCreateInstance( m_clsidPage, NULL, CLSCTX_INPROC, IID_IPropertyPage, (void**)&m_pPropPage ); if( FAILED( hRes ) ) AfxThrowOleException( hRes ); hRes = m_pPropPage->SetPageSite( (IPropertyPageSite*) GetInterface( &IID_IPropertyPageSite ) ); if( FAILED( hRes ) ) AfxThrowOleException( hRes ); hRes = m_pPropPage->SetObjects( count, m_pObject ); if( FAILED( hRes ) ) AfxThrowOleException( hRes ); IMalloc *pIMalloc; if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) AfxThrowOleException(E_FAIL); PROPPAGEINFO* pPPI = (PROPPAGEINFO*) pIMalloc->Alloc(sizeof(PROPPAGEINFO)); pPPI->cb = sizeof(PROPPAGEINFO); hRes = m_pPropPage->GetPageInfo(pPPI); #ifndef UNICODE m_strCaption.Format("%S", pPPI->pszTitle); #else m_strCaption = pPPI->pszTitle; #endif m_psp.pszTitle = m_strCaption; m_psp.dwFlags |= PSP_USETITLE; m_psp.hIcon = ::LoadIcon(NULL, IDI_QUESTION); pIMalloc->Free(pPPI); pIMalloc->Release(); } catch (COleException * e) { throw (e); } }
void CBoxHttpServer::AttachHost(LPCTSTR pstrName, LPDISPATCH pdispHost) { CBoxObject<CBoxHttpHost> pHost; pHost = pdispHost; if(pHost == NULL || !pHost->IsKindOf(RUNTIME_CLASS(CBoxHttpHost))) AfxThrowOleException(TYPE_E_TYPEMISMATCH); m_pContents->SetValue(pstrName, (LPDISPATCH)pHost); }
IOleObject *CImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage) { ASSERT(m_stgmed.hBitmap); SCODE sc; IOleObject *pOleObject; sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, &m_fromat, pOleClientSite, pStorage, (void **)&pOleObject); if (sc != S_OK) AfxThrowOleException(sc); return pOleObject; }
void AFX_CDECL CSaxModule::Set(LPCTSTR pszMemberName, const BYTE* pbParamInfo, ...) { DISPID dispidMember = GetDispId(pszMemberName); if (dispidMember == DISPID_UNKNOWN) AfxThrowOleException(DISP_E_MEMBERNOTFOUND); va_list argList; va_start(argList, pbParamInfo); InvokeHelperV(dispidMember, DISPATCH_PROPERTYPUTREF, VT_EMPTY, NULL, pbParamInfo, argList); va_end(argList); }
void CBoxHttpHost::AttachFolder(LPCTSTR pstrName, LPDISPATCH pdispHost) { CBoxObject<CBoxHttpHost> pHost; CString strName(pstrName); pHost = pdispHost; if(pHost == NULL || !pHost->IsKindOf(RUNTIME_CLASS(CBoxHttpHost))) AfxThrowOleException(TYPE_E_TYPEMISMATCH); strName.Replace('/', '\\'); m_pContents->SetValue(strName, (LPDISPATCH)pHost); }
void COleServerItem::OnDoVerb(LONG iVerb) { switch (iVerb) { // open - maps to OnOpen case OLEIVERB_OPEN: case -OLEIVERB_OPEN-1: // allows positive OLEIVERB_OPEN-1 in registry OnOpen(); break; // primary, show, and unknown map to OnShow case OLEIVERB_PRIMARY: // OLEIVERB_PRIMARY is 0 and "Edit" in registry case OLEIVERB_SHOW: OnShow(); break; // hide maps to OnHide case OLEIVERB_HIDE: case -OLEIVERB_HIDE-1: // allows positive OLEIVERB_HIDE-1 in registry OnHide(); break; default: // negative verbs not understood should return E_NOTIMPL if (iVerb < 0) AfxThrowOleException(E_NOTIMPL); // positive verb not processed -- // according to OLE spec, primary verb should be executed // instead. OnDoVerb(OLEIVERB_PRIMARY); // also, OLEOBJ_S_INVALIDVERB should be returned. AfxThrowOleException(OLEOBJ_S_INVALIDVERB); } }
void CBoxHttpHost::AddURLRewriter(LPCTSTR pstrRE, LPCTSTR pstr) { HRESULT hr; CAtlRegExp<CURLRECharTraits> *pre; pre = new CAtlRegExp<CURLRECharTraits>; hr = pre->Parse(pstrRE, false); if(FAILED(hr)) { delete pre; AfxThrowOleException(hr); } m_areUrl.Add(pre); m_aUrl.Add(pstr); }
VARIANT AFX_CDECL CSaxModule::Evaluate(LPCTSTR pszMemberName, const BYTE* pbParamInfo, ...) { DISPID dispidMember = GetDispId(pszMemberName); if (dispidMember == DISPID_UNKNOWN) AfxThrowOleException(DISP_E_MEMBERNOTFOUND); va_list argList; va_start(argList, pbParamInfo); VARIANT var; VariantInit(&var); InvokeHelperV(dispidMember, DISPATCH_METHOD, VT_VARIANT, &var, pbParamInfo, argList); va_end(argList); return var; }
void COleDocument::SaveToStorage(CObject* pObject) { ASSERT(m_lpRootStg != NULL); // create Contents stream COleStreamFile file; CFileException fe; if (!file.CreateStream(m_lpRootStg, _T("Contents"), CFile::modeReadWrite|CFile::shareExclusive|CFile::modeCreate, &fe)) { if (fe.m_cause == CFileException::fileNotFound) AfxThrowArchiveException(CArchiveException::badSchema); else AfxThrowFileException(fe.m_cause, fe.m_lOsError); } // save to Contents stream CArchive saveArchive(&file, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; TRY { // save the contents if (pObject != NULL) pObject->Serialize(saveArchive); else Serialize(saveArchive); saveArchive.Close(); file.Close(); // commit the root storage SCODE sc = m_lpRootStg->Commit(STGC_ONLYIFCURRENT); if (sc != S_OK) AfxThrowOleException(sc); } CATCH_ALL(e) { file.Abort(); // will not throw an exception CommitItems(FALSE); // abort save in progress NO_CPP_EXCEPTION(saveArchive.Abort()); THROW_LAST(); } END_CATCH_ALL }
HRESULT CTCPropBagOnRegKey::_LogError(const _bstr_t& strFn, const _bstr_t& strDesc, HRESULT hr, LPCOLESTR pszPropName, IErrorLog* pErrorLog) { // Create the source string _bstr_t strSrc, strSubkey(GetSubkey()); if (!strSubkey.length()) strSrc.Format(_T("CTCPropBagOnRegKey::_%s(\"%ls\")"), strFn, pszPropName); else strSrc.Format(_T("CTCPropBagOnRegKey::_%s(\"%s\\%ls\")"), strFn, strSubkey, pszPropName); // Output a trace message under _DEBUG builds TRACE2("%s: %s\n", strSrc, strDesc); // Log an error, if an IErrorLog interface is specified if (NULL != pErrorLog) { // Allocate BSTR's from the formatted strings BSTR bstrSrc = strSrc.AllocSysString(); BSTR bstrDesc = strDesc.AllocSysString(); // Create an EXCEPINFO structure and log the error EXCEPINFO ei = {0, 0, bstrSrc, bstrDesc, NULL, 0, NULL, NULL, hr}; HRESULT hrAdd = pErrorLog->AddError(pszPropName, &ei); // Free the allocated BSTR's SysFreeString(bstrDesc); SysFreeString(bstrSrc); // Handle an unsuccessful IErrorLog::AddError call if (FAILED(hrAdd)) { TRACE1("%s: pErrorLog->AddError() failed!\n", strSrc); AfxThrowOleException(hrAdd); } } // Indicate failure return hr; }
COcsWmi::COcsWmi() { m_pIWbemServices = NULL; m_pEnumClassObject = NULL; m_pClassObject = NULL; m_hResult = CoInitializeEx(0, COINIT_MULTITHREADED); // Initialize COM. if (FAILED( m_hResult)) AfxThrowOleException( m_hResult); // Program has failed. }
BSTR CBoxEncoding::BinToStr(VARIANT& var, VARIANT &varCP) { CBoxBinPtr varPtr(var); UINT nCodePage; if(varCP.vt == VT_ERROR) nCodePage = _AtlGetConversionACP(); else { CComVariant varTemp; varTemp.ChangeType(VT_I4, &varCP); if(varTemp.vt == VT_I4) nCodePage = varTemp.lVal; else AfxThrowOleException(TYPE_E_TYPEMISMATCH); } int _nTempCount = ::MultiByteToWideChar(nCodePage, 0, varPtr, varPtr.m_nSize, NULL, NULL); BSTR bstr = ::SysAllocStringLen(NULL, _nTempCount); if(bstr != NULL) ::MultiByteToWideChar(nCodePage, 0, varPtr, varPtr.m_nSize, bstr, _nTempCount); return bstr; }
void CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) { SCODE sc; // Get the image data object // CImageDataObject *pods = new CImageDataObject; LPDATAOBJECT lpDataObject; pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject); pods->SetBitmap(hBitmap); // Get the RichEdit container site // IOleClientSite *pOleClientSite; pRichEditOle->GetClientSite(&pOleClientSite); // Initialize a Storage Object // IStorage *pStorage; LPLOCKBYTES lpLockBytes = NULL; sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); lpLockBytes = NULL; AfxThrowOleException(sc); } ASSERT(pStorage != NULL); // The final ole object which will be inserted in the richedit control // IOleObject *pOleObject; pOleObject = pods->GetOleObject(pOleClientSite, pStorage); if(!pOleObject) AfxThrowOleException(sc); // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(pOleObject, TRUE); // Now Add the object to the RichEdit // REOBJECT reobject; ZeroMemory(&reobject, sizeof(REOBJECT)); reobject.cbStruct = sizeof(REOBJECT); CLSID clsid; sc = pOleObject->GetUserClassID(&clsid); if (sc != S_OK) AfxThrowOleException(sc); reobject.clsid = clsid; reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.poleobj = pOleObject; reobject.polesite = pOleClientSite; reobject.pstg = pStorage; // Insert the bitmap at the current location in the richedit control // pRichEditOle->InsertObject(&reobject); // Release all unnecessary interfaces // pOleObject->Release(); pOleClientSite->Release(); pStorage->Release(); lpDataObject->Release(); }
BOOL CTreeItem::ExpandTypeInfo( HTREEITEM hitem ) { ASSERT(m_pTree) ; ASSERT(hitem) ; CTreeItem* pNewItem = NULL ; HRESULT hr = S_OK ; TV_INSERTSTRUCT tvis ; CString strError = "Enumerating TypeInfo" ; TYPEATTR* pattr = NULL ; ITypeInfo* pti = GetTypeInfo() ; ASSERT(pti) ; BOOL fExpand = FALSE ; tvis.hParent = hitem ; tvis.hInsertAfter = TVI_LAST ; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN ; tvis.item.iImage = typeUnknown ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; TRY { ENSURE(pti); hr = pti->GetTypeAttr(&pattr) ; if FAILED(hr) { strError.Format(_T("ITypeInfo::GetTypeAttr() failed"), hr ) ; AfxThrowMemoryException() ; } switch(pattr->typekind) { // typedef [attributes] enum [tag] { // enumlist // } enumname; // // "typedef enum enumname" case TKIND_ENUM: fExpand = ExpandVars( hitem ) ; break ; // typedef [attributes] // struct [tag] { // memberlist // } structname; // // "typedef struct structname" case TKIND_RECORD: fExpand = ExpandVars( hitem ) ; break ; // [attributes] // module modulename { // elementlist // }; case TKIND_MODULE: if (pattr->cVars) { // Add "Constants" folder // #pragma warning (suppress: 6211) #pragma warning (suppress: 6014) pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeProperties ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Constants") ; tvis.item.iImage = typeConstants ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cFuncs) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeMethods ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cFuncs ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Functions") ; tvis.item.iImage = typeMethods ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // interface interfacename [:baseinterface] { // functionlist // }; case TKIND_INTERFACE: fExpand = ExpandFuncs( hitem) ; if (pattr->cImplTypes) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeImplTypes ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.pszText = _T("Inherited Interfaces") ; tvis.item.iImage = typeInterface ; tvis.item.cChildren = pattr->cImplTypes ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // dispinterface intfname { // interface interfacename // }; case TKIND_DISPATCH : if (pattr->cVars) { // Add "Constants" folder // pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeConstants ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Constants") ; tvis.item.iImage = typeConstants ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; // Add "Properties" folder // pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeProperties ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Properties") ; tvis.item.iImage = typeProperties ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cFuncs) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeMethods ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cFuncs ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Methods") ; tvis.item.iImage = typeMethods ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cImplTypes) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeImplTypes ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.pszText = _T("Inherited Interfaces") ; tvis.item.iImage = typeInterface ; tvis.item.cChildren = pattr->cImplTypes ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // coclass classname { // [attributes2] [interface | dispinterface] interfacename; // ... // }; case TKIND_COCLASS: fExpand = ExpandImplTypes( hitem ) ; break ; // typedef [attributes] basetype aliasname; case TKIND_ALIAS: if (pattr->tdescAlias.vt == VT_USERDEFINED) { ITypeInfo* ptiRefType = NULL ; #pragma warning (suppress: 6246) HRESULT hr = pti->GetRefTypeInfo( pattr->tdescAlias.hreftype, &ptiRefType ) ; if (FAILED(hr)) AfxThrowOleException( hr ) ; pNewItem = new CTreeItem(m_pTree) ; pNewItem->SetTypeInfo( ptiRefType ) ; pNewItem->m_Type = TypeKindToItemType( pNewItem->GetTypeKind() ) ; tvis.item.iImage = TypeKindToItemType( pNewItem->GetTypeKind() ) ; tvis.item.cChildren = 1 ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; CString sName; pNewItem->GetName(sName, TRUE ); tvis.item.pszText = sName.GetBuffer(0) ; m_pTree->InsertItem( &tvis ) ; sName.ReleaseBuffer(); fExpand = TRUE ; } break ; // typedef [attributes] union [tag] { // memberlist // } unionname; case TKIND_UNION: fExpand = ExpandVars( hitem ) ; break ; default: break ; } if (pattr) pti->ReleaseTypeAttr( pattr ) ; } CATCH(CException, pException) { ErrorMessage( strError, hr ) ; if (pNewItem) delete pNewItem ; if (pattr) pti->ReleaseTypeAttr( pattr ) ; return FALSE ; }
BOOL CTreeItem::ExpandTypeLib( HTREEITEM hitem ) { ASSERT(hitem) ; CTreeItem* pNewItem = NULL ; UINT uiTypeInfoCount = GetTypeLib()->GetTypeInfoCount() ; HRESULT hr = S_OK ; TV_INSERTSTRUCT tvis ; CString strError = "Enumerating typeinfos"; TYPEATTR* pattr = NULL ; BOOL fExpand = FALSE ; tvis.hParent = hitem ; tvis.hInsertAfter = TVI_LAST ; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN ; tvis.item.cChildren = 1 ; TRY { for (UINT n = 0 ; n < uiTypeInfoCount ; n++) { #pragma warning (suppress: 6014) pNewItem = new CTreeItem( m_pTree ) ; pNewItem->m_Type = typeTypeInfo ; ASSERT(pNewItem) ; tvis.item.lParam = (LPARAM)pNewItem ; hr = GetTypeLib()->GetTypeInfo( n, (ITypeInfo**)&pNewItem->m_punk ) ; if (FAILED(hr)) { strError.Format(_T("Could not get TypeInfo #%u"), n ) ; AfxThrowOleException(hr) ; } ASSERT(pNewItem->m_punk) ; hr = pNewItem->GetTypeInfo()->GetTypeAttr(&pattr) ; if FAILED(hr) { strError.Format(_T("ITypeInfo::GetTypeAttr() failed") ) ; AfxThrowOleException(hr) ; } if ((m_Type == typeTypeLib) || (m_Type == (TypeKindToItemType(pattr->typekind) + 8))) { tvis.item.iImage = pattr->typekind + typeEnum ; tvis.item.iSelectedImage = tvis.item.iImage ; CString sName; pNewItem->GetName(sName, TRUE ); tvis.item.pszText = sName.GetBuffer(0); m_pTree->InsertItem( &tvis ) ; sName.ReleaseBuffer(); pNewItem->GetTypeInfo()->ReleaseTypeAttr( pattr ) ; fExpand = TRUE ; } else { pNewItem->GetTypeInfo()->ReleaseTypeAttr( pattr ) ; delete pNewItem ; } } } CATCH(CException, pException) { if (pException->IsKindOf(RUNTIME_CLASS(COleException))) ErrorMessage( strError, ((COleException*)pException)->m_sc ) ; else ErrorMessage( strError, hr ) ; if (pNewItem) delete pNewItem ; return FALSE ; } END_CATCH return fExpand ; }
BOOL CXTPCalendarTimeZones::InitFromRegistry() { m_arTZInfo.RemoveAll(); CString strTZIRootKey = XTP_CALENDAR_TIMEZONESKEY_NT; HKEY hkTZIRoot = NULL; BOOL bUseIndex = !XTPSystemVersion()->IsWinXPOrGreater(); // Try NT information first LONG lRes = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, strTZIRootKey, 0, KEY_READ, &hkTZIRoot); if (lRes != ERROR_SUCCESS) { // try Win9x information strTZIRootKey = XTP_CALENDAR_TIMEZONESKEY_9X; bUseIndex = FALSE; lRes = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, strTZIRootKey, 0, KEY_READ, &hkTZIRoot); if (lRes != ERROR_SUCCESS) { TRACE(_T("Cannot open Time Zones information registry key. err = %d \n"), lRes); return FALSE; } } const DWORD cdwKeyBufSize = 1024; TCHAR szTZIKey[cdwKeyBufSize + 1]; BSTR bstrStandardName = NULL; BSTR bstrDaylightName = NULL; lRes = ERROR_SUCCESS; for (DWORD dwEnumKey = 0; lRes == ERROR_SUCCESS; dwEnumKey++) { ::ZeroMemory(szTZIKey, sizeof(szTZIKey)); lRes = ::RegEnumKey (hkTZIRoot, dwEnumKey, szTZIKey, cdwKeyBufSize); if (lRes != ERROR_SUCCESS) { ASSERT(lRes == ERROR_NO_MORE_ITEMS); break; } //=================================================================== CString strTZIKey = strTZIRootKey + _T("\\") + szTZIKey; HKEY hkTZIdata = NULL; LONG lRes2 = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, strTZIKey, 0, KEY_READ, &hkTZIdata); if (lRes2 != ERROR_SUCCESS) { TRACE(_T("Cannot open registry key 'HKEY_LOCAL_MACHINE\\%s'. err = %d \n"), (LPCTSTR)strTZIKey, lRes2); continue; } CString strDisplayStr, strStandardName, strDaylightName; DWORD dwIndex; REGISTRY_TIMEZONE_INFORMATION regTZI; if (!GetRegStr(hkTZIdata, XTP_CALENDAR_TZIRegValName_DisplayStr, strDisplayStr)) { TRACE(_T("Cannot get value from registry: 'HKEY_LOCAL_MACHINE\\%s\\%s'\n"), (LPCTSTR)strTZIKey, XTP_CALENDAR_TZIRegValName_DisplayStr); continue; } if (!GetRegBSTR(hkTZIdata, XTP_CALENDAR_TZIRegValName_StandardNameW, bstrStandardName)) { TRACE(_T("Cannot get value from registry: 'HKEY_LOCAL_MACHINE\\%s\\%s'\n"), (LPCTSTR)strTZIKey, XTP_CALENDAR_TZIRegValName_StandardName); continue; } if (!GetRegBSTR(hkTZIdata, XTP_CALENDAR_TZIRegValName_DaylightNameW, bstrDaylightName)) { TRACE(_T("Cannot get value from registry: 'HKEY_LOCAL_MACHINE\\%s\\%s'\n"), (LPCTSTR)strTZIKey, XTP_CALENDAR_TZIRegValName_DaylightName); continue; } if (!GetRegTZI(hkTZIdata, XTP_CALENDAR_TZIRegValName_DATA, regTZI)) { TRACE(_T("Cannot get value from registry: 'HKEY_LOCAL_MACHINE\\%s\\%s'\n"), (LPCTSTR)strTZIKey, XTP_CALENDAR_TZIRegValName_DATA); continue; } if (!GetRegDWORD(hkTZIdata, XTP_CALENDAR_TZIRegValName_Index, dwIndex)) { if (bUseIndex) { TRACE(_T("Cannot get value from registry: 'HKEY_LOCAL_MACHINE\\%s\\%s'\n"), (LPCTSTR)strTZIKey, XTP_CALENDAR_TZIRegValName_Index); } dwIndex = 0; } //================================================= CXTPCalendarTimeZone* pXTP_TZI; pXTP_TZI = new CXTPCalendarTimeZone(); if (!pXTP_TZI) { AfxThrowOleException(E_OUTOFMEMORY); } pXTP_TZI->Bias = regTZI.Bias; WCSNCPY_S(pXTP_TZI->StandardName, 32, bstrStandardName, 32); pXTP_TZI->StandardName[_countof(pXTP_TZI->StandardName)-1] = L'\0'; pXTP_TZI->StandardDate = regTZI.StandardDate; pXTP_TZI->StandardBias = regTZI.StandardBias; WCSNCPY_S(pXTP_TZI->DaylightName, 32, bstrDaylightName, 32); pXTP_TZI->DaylightName[_countof(pXTP_TZI->DaylightName)-1] = L'\0'; pXTP_TZI->DaylightDate = regTZI.DaylightDate; pXTP_TZI->DaylightBias = regTZI.DaylightBias; pXTP_TZI->m_strDisplayString = strDisplayStr; pXTP_TZI->m_dwIndex = dwIndex; m_arTZInfo.Add(pXTP_TZI, FALSE); RegCloseKey(hkTZIdata); } RegCloseKey(hkTZIRoot); //----------------------------------------------- if (bstrStandardName) { ::SysFreeString(bstrStandardName); } if (bstrDaylightName) { ::SysFreeString(bstrDaylightName); } //----------------------------------------------- int nCount = m_arTZInfo.GetCount(); for (int i = 0; i < nCount; i++) { for (int j = i + 1; j < nCount; j++) { CXTPCalendarTimeZonePtr ptrElem1, ptrElem2; ptrElem1 = m_arTZInfo.GetAt(i, TRUE); ptrElem2 = m_arTZInfo.GetAt(j, TRUE); if (CompareTZI(ptrElem1, ptrElem2, bUseIndex) > 0) { m_arTZInfo.SetAt(i, ptrElem2.Detach()); m_arTZInfo.SetAt(j, ptrElem1.Detach()); } } } return TRUE; }
void CExtRichEdit::InsertFace(CString strPicPath) { LPLOCKBYTES lpLockBytes = NULL; SCODE sc; HRESULT hr; //print to RichEdit' s IClientSite LPOLECLIENTSITE m_lpClientSite; //A smart point to IAnimator IGifAnimatorPtr m_lpAnimator; //ptr 2 storage LPSTORAGE m_lpStorage; //the object 2 b insert 2 LPOLEOBJECT m_lpObject; //Create lockbytes sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); //use lockbytes to create storage sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); lpLockBytes = NULL; AfxThrowOleException(sc); } ASSERT(m_lpStorage != NULL); //get the ClientSite of the very RichEditCtrl GetIRichEditOle()->GetClientSite(&m_lpClientSite); ASSERT(m_lpClientSite != NULL); try { //Initlize COM interface hr = ::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); if( FAILED(hr) ) _com_issue_error(hr); //Get GifAnimator object //here, I used a smart point, so I do not need to free it hr = m_lpAnimator.CreateInstance(CLSID_GifAnimator); if( FAILED(hr) ) _com_issue_error(hr); //COM operation need BSTR, so get a BSTR BSTR path = strPicPath.AllocSysString(); //Load the gif hr = m_lpAnimator->LoadFromFile(path); if( FAILED(hr) ) _com_issue_error(hr); // TRACE0( m_lpAnimator->GetFilePath() ); //get the IOleObject hr = m_lpAnimator.QueryInterface(IID_IOleObject, (void**)&m_lpObject); if( FAILED(hr) ) _com_issue_error(hr); //Set it 2 b inserted OleSetContainedObject(m_lpObject, TRUE); //2 insert in 2 richedit, you need a struct of REOBJECT REOBJECT reobject; ZeroMemory(&reobject, sizeof(REOBJECT)); reobject.cbStruct = sizeof(REOBJECT); CLSID clsid; sc = m_lpObject->GetUserClassID(&clsid); if (sc != S_OK) AfxThrowOleException(sc); //set clsid reobject.clsid = clsid; //can be selected reobject.cp = REO_CP_SELECTION; //content, but not static reobject.dvaspect = DVASPECT_CONTENT; //goes in the same line of text line reobject.dwFlags = REO_BELOWBASELINE; //REO_RESIZABLE | reobject.dwUser = 0; //the very object reobject.poleobj = m_lpObject; //client site contain the object reobject.polesite = m_lpClientSite; //the storage reobject.pstg = m_lpStorage; SIZEL sizel; sizel.cx = sizel.cy = 0; reobject.sizel = sizel; HWND hWndRT = this->m_hWnd; //Sel all text // ::SendMessage(hWndRT, EM_SETSEL, 0, -1); // DWORD dwStart, dwEnd; // ::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); // ::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1); //Insert after the line of text GetIRichEditOle()->InsertObject(&reobject); ::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); VARIANT_BOOL ret; //do frame changing ret = m_lpAnimator->TriggerFrameChange(); //show it m_lpObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_lpClientSite, 0, m_hWnd, NULL); m_lpObject->DoVerb(OLEIVERB_SHOW, NULL, m_lpClientSite, 0, m_hWnd, NULL); //redraw the window to show animation RedrawWindow(); if (m_lpClientSite) { m_lpClientSite->Release(); m_lpClientSite = NULL; } if (m_lpObject) { m_lpObject->Release(); m_lpObject = NULL; } if (m_lpStorage) { m_lpStorage->Release(); m_lpStorage = NULL; } SysFreeString(path); } catch( _com_error e ) { AfxMessageBox(e.ErrorMessage()); ::CoUninitialize(); } }
void CNetscapeSrvrItem::OnDoVerb(LONG iVerb) { switch (iVerb) { // open - maps to OnOpen case OLEIVERB_OPEN: case -OLEIVERB_OPEN-1: // allows positive OLEIVERB_OPEN-1 in registry OnOpen(); break; // primary, show, and unknown map to OnShow case OLEIVERB_PRIMARY: // OLEIVERB_PRIMARY is 0 and "Edit" in registry case OLEIVERB_SHOW: case OLEIVERB_UIACTIVATE: { COleServerDoc* pDoc = GetDocument(); m_ShowUI = TRUE; OnShow(); break; } case OLEIVERB_INPLACEACTIVATE: { COleServerDoc* pDoc = GetDocument(); m_ShowUI = FALSE; OnShow(); break; } // hide maps to OnHide case OLEIVERB_HIDE: case -OLEIVERB_HIDE-1: // allows positive OLEIVERB_HIDE-1 in registry OnHide(); break; case NO_UI_EMBEDDING: { //Get InPlaceFrame ptr. CGenericDoc *pDoc = GetDocument(); ASSERT(pDoc); POSITION pos = pDoc->GetFirstViewPosition(); CView *pView = pDoc->GetNextView(pos); ASSERT(pView); m_ShowUI = FALSE; OnShow(); CInPlaceFrame *pFrm = (CInPlaceFrame *)pView->GetParent(); ASSERT(pFrm); pFrm->DestroyResizeBar(); break; } default: // negative verbs not understood should return E_NOTIMPL if (iVerb < 0) AfxThrowOleException(E_NOTIMPL); // positive verb not processed -- // according to OLE spec, primary verb should be executed // instead. OnDoVerb(OLEIVERB_PRIMARY); // also, OLEOBJ_S_INVALIDVERB should be returned. AfxThrowOleException(OLEOBJ_S_INVALIDVERB); } }
void CStringCollect::CheckIndex(long nIndex) { if (nIndex <= 0 || nIndex > m_strArray.GetSize()) AfxThrowOleException(E_INVALIDARG); }