SCODE AFXAPI _AfxOleDoTreatAsClass( LPCTSTR lpszUserType, REFCLSID rclsid, REFCLSID rclsidNew) { LPTSTR lpszCLSID = NULL; HKEY hKey; SCODE sc = CoTreatAsClass(rclsid, rclsidNew); if (sc != S_OK && lpszUserType != NULL) { RegOpenKey(HKEY_CLASSES_ROOT, _T("CLSID"), &hKey); LPOLESTR lpOleStr = NULL; StringFromCLSID(rclsid, &lpOleStr); lpszCLSID = TASKSTRINGOLE2T(lpOleStr); RegSetValue(hKey, lpszCLSID, REG_SZ, lpszUserType, lstrlen(lpszUserType) * sizeof(TCHAR)); CoTaskMemFree(lpszCLSID); sc = CoTreatAsClass(rclsid, rclsidNew); RegCloseKey(hKey); } return sc; }
COleConvertDialog::COleConvertDialog(COleClientItem* pItem, DWORD dwFlags, CLSID* pClassID, CWnd* pParentWnd) : COleDialog(pParentWnd) { if (pItem != NULL) ASSERT_VALID(pItem); ASSERT(pClassID == NULL || AfxIsValidAddress(pClassID, sizeof(CLSID), FALSE)); memset(&m_cv, 0, sizeof(m_cv)); // initialize structure to 0/NULL if (pClassID != NULL) m_cv.clsid = *pClassID; // fill in common part m_cv.cbStruct = sizeof(m_cv); m_cv.dwFlags = dwFlags; if (!afxData.bWin4 && AfxHelpEnabled()) m_cv.dwFlags |= CF_SHOWHELPBUTTON; m_cv.lpfnHook = AfxOleHookProc; m_nIDHelp = AFX_IDD_CONVERT; // specific to this dialog m_cv.fIsLinkedObject = pItem->GetType() == OT_LINK; m_cv.dvAspect = pItem->GetDrawAspect(); if (pClassID == NULL && !m_cv.fIsLinkedObject) { // for embeddings, attempt to get class ID from the storage if (ReadClassStg(pItem->m_lpStorage, &m_cv.clsid) == S_OK) pClassID = &m_cv.clsid; // attempt to get user type from storage CLIPFORMAT cf = 0; LPOLESTR lpOleStr = NULL; ReadFmtUserTypeStg(pItem->m_lpStorage, &cf, &lpOleStr); m_cv.lpszUserType = TASKSTRINGOLE2T(lpOleStr); m_cv.wFormat = (WORD)cf; } // get class id if neded if (pClassID == NULL) { // no class ID in the storage, use class ID of the object pItem->GetClassID(&m_cv.clsid); } // get user type if needed if (m_cv.lpszUserType == NULL) { // no user type in storge, get user type from class ID LPTSTR lpszUserType = NULL; LPOLESTR lpOleStr = NULL; if (OleRegGetUserType(m_cv.clsid, USERCLASSTYPE_FULL, &lpOleStr) == S_OK) { lpszUserType = TASKSTRINGOLE2T(lpOleStr); } else { lpszUserType = (LPTSTR)CoTaskMemAlloc(256 * sizeof(TCHAR)); if (lpszUserType != NULL) { lpszUserType[0] = '?'; lpszUserType[1] = 0; VERIFY(AfxLoadString(AFX_IDS_UNKNOWNTYPE, lpszUserType) != 0); } } m_cv.lpszUserType = lpszUserType; } m_cv.hMetaPict = pItem->GetIconicMetafile(); }
STDMETHODIMP COleUILinkInfo::GetLinkSource( DWORD dwLink, LPTSTR* lplpszDisplayName, ULONG* lplenFileName, LPTSTR* lplpszFullLinkType, LPTSTR* lplpszShortLinkType, BOOL* lpfSourceAvailable, BOOL* lpfIsSelected) { COleClientItem* pItem = (COleClientItem*)dwLink; ASSERT_VALID(pItem); ASSERT_KINDOF(COleClientItem, pItem); ASSERT(pItem->GetType() == OT_LINK); // set OUT params to NULL ASSERT(lplpszDisplayName != NULL); *lplpszDisplayName = NULL; if (lplpszFullLinkType != NULL) *lplpszFullLinkType = NULL; if (lplpszShortLinkType != NULL) *lplpszShortLinkType = NULL; if (lplenFileName != NULL) *lplenFileName = 0; if (lpfSourceAvailable != NULL) *lpfSourceAvailable = !pItem->m_bLinkUnavail; // get IOleLink interface LPOLELINK lpOleLink = QUERYINTERFACE(pItem->m_lpObject, IOleLink); ASSERT(lpOleLink != NULL); // get moniker & object information LPMONIKER lpmk; if (lpOleLink->GetSourceMoniker(&lpmk) == S_OK) { if (lplenFileName != NULL) *lplenFileName = _AfxOleGetLenFilePrefixOfMoniker(lpmk); lpmk->Release(); } // attempt to get the type names of the link if (lplpszFullLinkType != NULL) { LPOLESTR lpOleStr = NULL; pItem->m_lpObject->GetUserType(USERCLASSTYPE_FULL, &lpOleStr); *lplpszFullLinkType = TASKSTRINGOLE2T(lpOleStr); if (*lplpszFullLinkType == NULL) { TCHAR szUnknown[256]; VERIFY(AfxLoadString(AFX_IDS_UNKNOWNTYPE, szUnknown) != 0); *lplpszFullLinkType = AfxAllocTaskString(szUnknown); } } if (lplpszShortLinkType != NULL) { LPOLESTR lpOleStr = NULL; pItem->m_lpObject->GetUserType(USERCLASSTYPE_SHORT, &lpOleStr); *lplpszShortLinkType = TASKSTRINGOLE2T(lpOleStr); if (*lplpszShortLinkType == NULL) { TCHAR szUnknown[256]; VERIFY(AfxLoadString(AFX_IDS_UNKNOWNTYPE, szUnknown) != 0); *lplpszShortLinkType = AfxAllocTaskString(szUnknown); } } // get source display name for moniker LPOLESTR lpOleStr = NULL; SCODE sc = lpOleLink->GetSourceDisplayName(&lpOleStr); *lplpszDisplayName = TASKSTRINGOLE2T(lpOleStr); lpOleLink->Release(); if (sc != S_OK) return sc; // see if item is selected if specified if (lpfIsSelected) { *lpfIsSelected = (m_pSelectedItem == pItem); } return S_OK; }
STDMETHODIMP COlePropertiesDialog::XOleUIObjInfo::GetObjectInfo( DWORD dwObject, DWORD* lpdwObjSize, LPTSTR* lplpszLabel, LPTSTR* lplpszType, LPTSTR* lplpszShortType, LPTSTR* lplpszLocation) { COleClientItem* pItem = (COleClientItem*)dwObject; ASSERT_VALID(pItem); BOOL bIsLink = (pItem->GetType() == OT_LINK); if (lpdwObjSize != NULL) { ASSERT(pItem->m_lpStorage != NULL); // try ILockBytes first, then IStorage STATSTG statStg; if ((pItem->m_lpLockBytes == NULL || pItem->m_lpLockBytes->Stat(&statStg, STATFLAG_NONAME) != S_OK) && pItem->m_lpStorage->Stat(&statStg, STATFLAG_NONAME) != S_OK) { *lpdwObjSize = 0xFFFFFFFF; } else { ASSERT(statStg.pwcsName == NULL); if (statStg.cbSize.HighPart > 0) *lpdwObjSize = 0xFFFFFFFE; else if (statStg.cbSize.LowPart == 0) *lpdwObjSize = 0xFFFFFFFF; else *lpdwObjSize = statStg.cbSize.LowPart; } } if (lplpszLabel != NULL) { TCHAR szFormatLink[128]; AfxLoadString(AFX_IDS_PASTELINKEDTYPE, szFormatLink, _countof(szFormatLink)); TCHAR szFormatObj[] = _T("%s"); LPTSTR lpszFormat = bIsLink ? szFormatLink : szFormatObj; CString strType; pItem->GetUserType(USERCLASSTYPE_FULL, strType); CString strResult; strResult.Format(lpszFormat, (LPCTSTR)strType); *lplpszLabel = AfxAllocTaskString(strResult); } if (lplpszType != NULL) { LPOLESTR lpOleStr; pItem->m_lpObject->GetUserType(USERCLASSTYPE_FULL, &lpOleStr); *lplpszType = TASKSTRINGOLE2T(lpOleStr); } if (lplpszShortType != NULL) { LPOLESTR lpOleStr; pItem->m_lpObject->GetUserType(USERCLASSTYPE_SHORT, &lpOleStr); *lplpszShortType = TASKSTRINGOLE2T(lpOleStr); } if (lplpszLocation != NULL) { if (bIsLink) { LPOLELINK lpOleLink = NULL; pItem->m_lpObject->QueryInterface(IID_IOleLink, (LPVOID*)&lpOleLink); ASSERT(lpOleLink != NULL); LPOLESTR lpOleStr; lpOleLink->GetSourceDisplayName(&lpOleStr); *lplpszLocation = TASKSTRINGOLE2T(lpOleStr); lpOleLink->Release(); } else { CDocument* pDoc = (CDocument*)pItem->GetDocument(); CString strLocation = pDoc->GetPathName(); if (strLocation.IsEmpty()) strLocation = pDoc->GetTitle(); *lplpszLocation = AfxAllocTaskString(strLocation); } } return S_OK; }