HRESULT CTCPropBagOnRegKey::_GetObjectCLSID(const _bstr_t& strName,
  CLSID& clsid, CRegKey& subkey, _bstr_t& strObjectID, IErrorLog* pErrorLog)
{
  USES_CONVERSION;

  // Clear the specified clsid, subkey, and strObjectID parameters
  clsid = CLSID_NULL;
  subkey.Close();
  strObjectID.Empty();

  // Open the subkey with the specified name
  if (!strName.length())
    subkey = m_key;
  else if (!m_key.Exists(strName) || !subkey.Open(m_key, strName))
    return HRESULT_FROM_WIN32(GetLastError());

  // Use local resources for string loading
  MCLibRes res;

  // Read the object's CLSID string value
  HRESULT hr;
  _bstr_t strDesc;
  if (subkey.GetString(m_szCLSID, strObjectID))
  {
    // Convert the object's CLSID string to a CLSID
    LPOLESTR pszObjectID = const_cast<LPOLESTR>(T2COLE(strObjectID));
    hr = CLSIDFromString(pszObjectID, &clsid);
    if (SUCCEEDED(hr))
      return hr;

    // Format an error description string   
    strDesc.Format(IDS_FMT_FAIL_CONVERT_CLSID, strObjectID);
  }
  else if (subkey.GetString(m_szProgID, strObjectID))
  {
    // Convert the object's ProgID string to a CLSID
    hr = CLSIDFromProgID(T2COLE(strObjectID), &clsid);
    if (SUCCEEDED(hr))
      return hr;

    // Format an error description string
    strDesc.Format(IDS_FMT_FAIL_CONVERT_CLSID, strObjectID);
  }
  else
  {
    // Save the last error
    hr = HRESULT_FROM_WIN32(GetLastError());

    // Format an error description string
    strDesc.LoadString(IDS_FAIL_READ_CLSID);
  }

  // Log the error and return
  return LogError("GetObjectCLSID", strDesc, hr, T2COLE(strName), pErrorLog);
}
HRESULT AFXAPI AfxGetClassIDFromString(LPCTSTR lpsz, LPCLSID lpClsID)
{
	USES_CONVERSION;

	HRESULT hr;
	if (lpsz[0] == '{')
		hr = CLSIDFromString((LPOLESTR)T2COLE(lpsz), lpClsID);
	else
		hr = CLSIDFromProgID(T2COLE(lpsz), lpClsID);
	return hr;
}
示例#3
0
BOOL CComDateTime::ParseDateTime(LPCTSTR lpszDate, DWORD dwFlags, LCID lcid)
{
	USES_CONVERSION;
	SCODE sc = VarDateFromStr((LPOLESTR)T2COLE(lpszDate), lcid, dwFlags, &m_dt);
	if (FAILED(sc))
	{
		if (sc == DISP_E_TYPEMISMATCH)
		{
			// Can't convert string to date, set 0 and invalidate
			m_dt = 0;
			SetStatus(invalid);
			return FALSE;
		}
		else  // if (sc == DISP_E_OVERFLOW)
		{
			// Can't convert string to date, set -1 and invalidate
			m_dt = -1;
			SetStatus(invalid);
			return FALSE;
		}
	}

	SetStatus(valid);
	return TRUE;
}
void RegisterMonolithicDPlay()
{
	HKEY hKey = NULL;
	const char * szKey = "CLSID\\{DA9CABC6-C724-4265-A61D-6E78EB2042B4}\\InprocServer32";
	// check to see if it's already registered, and if so, do nothing, otherwise register it
	if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hKey))
	{
		// Get the module path
		TCHAR szFilePath[_MAX_PATH * 2], szDrive[_MAX_DRIVE], szDir[_MAX_DIR * 2];
		::GetModuleFileName(NULL, szFilePath, sizeofArray(szFilePath));
		_tsplitpath(szFilePath, szDrive, szDir, NULL, NULL);
		_tmakepath(szFilePath, szDrive, szDir, NULL, NULL);
		int cch = _tcslen(szFilePath);
		if (TEXT('\\') == szFilePath[cch - 1])
			szFilePath[cch - 1] = TEXT('\0');

		// Update the registry from the DPMono.rgs
		USES_CONVERSION;
		_ATL_REGMAP_ENTRY regmap[] =
		{
		  {L"MODULE_PATH", T2COLE(szFilePath)},
		  {NULL          ,               NULL},
		};
		_Module.UpdateRegistryFromResource(IDR_DPMONO, true, regmap);
	}
	else
	{
		RegCloseKey(hKey);
	}
}
示例#5
0
LRESULT COleIPFrameWnd::OnSetMessageString(WPARAM wParam, LPARAM lParam)
{
	USES_CONVERSION;

	if (m_lpFrame != NULL)
	{
		LPCTSTR lpsz = NULL;
		CString strMessage;

		// set the message bar text
		if (lParam != NULL)
		{
			ASSERT(wParam == 0);    // can't have both an ID and a string
			lpsz = (LPCTSTR)lParam; // set an explicit string
		}
		else if (wParam != 0)
		{
			// get message associated with the ID indicated by wParam
			GetMessageString(wParam, strMessage);
			lpsz = strMessage;
		}

		// notify container of new status text
		if (lpsz == NULL)
			lpsz = &afxChNil;
		m_lpFrame->SetStatusText(T2COLE(lpsz));
	}

	UINT nIDLast = m_nIDLastMessage;
	m_nIDLastMessage = (UINT)wParam;    // new ID (or 0)
	m_nIDTracking = (UINT)wParam;       // so F1 on toolbar buttons work
	return nIDLast;
}
void OleStorageOnDiskImpl::Open(const std::tstring& fileName)
{
	USES_CONVERSION;
	
	IStorage* pStorage;	
   HRESULT hr = ::StgOpenStorage(T2COLE(fileName.c_str()), 0, STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStorage);
   if(FAILED(hr))
   {
      std::tostringstream msg;
      switch (hr)
      {
         case STG_E_FILEALREADYEXISTS:
                 msg << _T("File [") << fileName.c_str() << _T("] exists but is not a storage object.") << std::ends;
                 throw Workshare::FileFormatNotSupportedException(fileName.c_str(), _T(""), msg.str().c_str());
         case STG_E_FILENOTFOUND:
         case STG_E_PATHNOTFOUND:
                 msg << _T("File [") << fileName.c_str() << _T("] not found.") << std::ends;
                 break;
         default:
                 msg << _T("Error occurred opening storage on file [") << fileName.c_str() << _T("].") << std::ends;
                 break;
      }

      throw Workshare::System::SystemException(msg.str().c_str(), hr);
   }
   m_spStorage = IStoragePtr(pStorage, false);
}
示例#7
0
RImage* QSLItemData::Load(
	CString& strDocPathname,		// @parm string containing document pathname
	BOOL     fDescOnly )
{
    USES_CONVERSION;

	LPSTORAGE	pIStorage = NULL;

	// get path name in Unicode
	const WCHAR *pDocPathname = T2COLE((LPCTSTR)strDocPathname.GetBuffer (10));
	strDocPathname.ReleaseBuffer();

	// open storage
	StgOpenStorage( pDocPathname, NULL, STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pIStorage );

	if (!pIStorage)
		return NULL ;

	RImage* pImage = Load2( pIStorage, fDescOnly );
	
	if (dynamic_cast<RBitmapImage *>( pImage ))
		((RBitmapImage *) pImage)->LockImage();

	// release storage
	pIStorage->Release();

	return( pImage );
}
示例#8
0
STDMETHODIMP CShellExt::XToolTipExt::GetInfoTip(DWORD dwFlags, LPWSTR *ppwszTip)
{
    METHOD_PROLOGUE(CShellExt, ToolTipExt);

    if ((_tcslen(pThis->m_szFile) == 0)||(!IsPathInAfs(pThis->m_szFile)))
    {
        *ppwszTip=NULL;
        return S_OK;
    }
    bool bIsSymlink = !!IsSymlink(pThis->m_szFile);
    bool bIsMountpoint = !!IsMountPoint(pThis->m_szFile);
    if ((!bIsSymlink) && (!bIsMountpoint))
    {
	*ppwszTip=NULL;
	return S_OK;
    }
    USES_CONVERSION;
    // dwFlags is currently unused.
    CString sInfo;
    if (bIsSymlink)
        sInfo = GetSymlink(pThis->m_szFile);
    else if (bIsMountpoint)
        sInfo = GetMountpoint(pThis->m_szFile);
    *ppwszTip = (WCHAR*) (pThis->m_pAlloc)->Alloc((1+sInfo.GetLength())*sizeof(WCHAR));
    if (*ppwszTip)
        wcscpy(*ppwszTip, (WCHAR*)T2COLE((LPCTSTR)sInfo));

    return S_OK;
}
示例#9
0
文件: DbOledb.cpp 项目: okigan/dblib
BOOL COledbRecordset::Open(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb==NULL || m_pDb->IsOpen());
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
   HRESULT Hr;

   // Close old recordset
   Close();

   m_nRowsAffected = 0;

   // Create a new recordset
   CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
   if( spCreate == NULL ) return FALSE;
   CComPtr<ICommand> spCommand;
   Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
   if( FAILED(Hr) ) return _Error(Hr);
   // Set type
   COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
   // Set SQL
   CComQIPtr<ICommandText> spText = spCommand;
   _ASSERTE(spText);
   USES_CONVERSION;
   Hr = spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
   if( FAILED(Hr) ) return _Error(Hr);

   // Execute...
   Hr = spText->Execute(NULL, IID_IRowset, NULL, &m_nRowsAffected, (LPUNKNOWN*) &m_spRowset);
   if( FAILED(Hr) ) return _Error(Hr);

   // Bind columns
   if( !_BindColumns() ) return FALSE;

   return MoveNext();
}
示例#10
0
void COleDocument::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)
{
	USES_CONVERSION;

	CDocument::SetPathName(lpszPathName, bAddToMRU);

	// update all of the objects' host names
	POSITION pos = GetStartPosition();
	COleClientItem* pItem;
	while ((pItem = GetNextClientItem(pos)) != NULL)
	{
		// update that item's host names
		pItem->m_lpObject->SetHostNames(T2COLE(AfxGetAppName()),
			T2COLE(m_strTitle));
	}
}
示例#11
0
//------------------------------------------------------------------------//
BOOL CBCGPGlobalUtils::DecimalFromString(DECIMAL& decimal, LPCTSTR psz)
{
	USES_CONVERSION;

	if (psz == NULL || _tcslen (psz) == 0)
	{
		psz = _T("0");
	}

	VARIANTARG varBstr;
	VARIANTARG varDecimal;
	AfxVariantInit(&varBstr);
	AfxVariantInit(&varDecimal);
	V_VT(&varBstr) = VT_BSTR;
	V_BSTR(&varBstr) = SysAllocString(T2COLE(psz));
	if (FAILED(VariantChangeType(&varDecimal, &varBstr, 0, VT_DECIMAL)))
	{
		VariantClear(&varBstr);
		VariantClear(&varDecimal);
		return FALSE;
	}
	decimal = V_DECIMAL(&varDecimal);
	VariantClear(&varBstr);
	VariantClear(&varDecimal);
	return TRUE;
}
示例#12
0
HRESULT STDMETHODCALLTYPE CHotKeyX::get_VirtKey2( BSTR __RPC_FAR *pstrKey )
{
   TCHAR sz[ 2 ] = { (TCHAR)m_cmHotKey.nVirtKey2, _T('\0') };
   USES_CONVERSION;
   *pstrKey = SysAllocString( T2COLE( sz ) );
   return S_OK;
}
示例#13
0
//------------------------------------------------------------------------//
BOOL CBCGPGlobalUtils::CyFromString(CY& cy, LPCTSTR psz)
{
	USES_CONVERSION;

	if (psz == NULL || _tcslen (psz) == 0)
	{
		psz = _T("0");
	}

	VARIANTARG varBstr;
	VARIANTARG varCy;
	AfxVariantInit(&varBstr);
	AfxVariantInit(&varCy);
	V_VT(&varBstr) = VT_BSTR;
	V_BSTR(&varBstr) = SysAllocString(T2COLE(psz));
	if (FAILED(VariantChangeType(&varCy, &varBstr, 0, VT_CY)))
	{
		VariantClear(&varBstr);
		VariantClear(&varCy);
		return FALSE;
	}
	cy = V_CY(&varCy);
	VariantClear(&varBstr);
	VariantClear(&varCy);
	return TRUE;
}
示例#14
0
void CSysProgressDlg::SetCancelMsg(LPCTSTR szMessage)
{
    USES_CONVERSION;
	if (m_bValid)
	{
		m_pIDlg->SetCancelMsg(T2COLE(szMessage), NULL);
	}
}
示例#15
0
void CSysProgressDlg::SetTitle(LPCTSTR szTitle)
{
    USES_CONVERSION;
    if (m_bValid)
	{
		m_pIDlg->SetTitle(T2COLE(szTitle));
	}
}
示例#16
0
void CSysProgressDlg::SetCancelMsg(LPCTSTR szMessage)
{
	USES_CONVERSION;
	if (IsValid())
	{
		m_pIDlg->SetCancelMsg(T2COLE(szMessage), nullptr);
	}
}
示例#17
0
void CSysProgressDlg::SetLine(DWORD dwLine, LPCTSTR szText, bool bCompactPath /* = false */)
{
	USES_CONVERSION;
	if (m_bValid)
	{
		m_pIDlg->SetLine(dwLine, T2COLE(szText), bCompactPath, NULL);
	}
}
示例#18
0
文件: ctlreg.cpp 项目: Rupan/winscp
BOOL AFXAPI AfxOleRegisterTypeLib(HINSTANCE hInstance, REFGUID tlid,
	LPCTSTR pszFileName, LPCTSTR pszHelpDir)
{
	USES_CONVERSION;

	BOOL bSuccess = FALSE;
	CString strPathName;
	TCHAR *szPathName = strPathName.GetBuffer(_MAX_PATH);
	::GetModuleFileName(hInstance, szPathName, _MAX_PATH);
	strPathName.ReleaseBuffer();
	LPTYPELIB ptlib = NULL;

	// If a filename was specified, replace final component of path with it.
	if (pszFileName != NULL)
	{
		int iBackslash = strPathName.ReverseFind('\\');
		if (iBackslash != -1)
			strPathName = strPathName.Left(iBackslash+1);
		strPathName += pszFileName;
	}

	if (SUCCEEDED(LoadTypeLib(T2COLE(strPathName), &ptlib)))
	{
		ASSERT_POINTER(ptlib, ITypeLib);

		LPTLIBATTR pAttr;
		GUID tlidActual = GUID_NULL;

		if (SUCCEEDED(ptlib->GetLibAttr(&pAttr)))
		{
			ASSERT_POINTER(pAttr, TLIBATTR);
			tlidActual = pAttr->guid;
			ptlib->ReleaseTLibAttr(pAttr);
		}

		// Check that the guid of the loaded type library matches
		// the tlid parameter.
		ASSERT(IsEqualGUID(tlid, tlidActual));

		if (IsEqualGUID(tlid, tlidActual))
		{
			// Register the type library.
			if (SUCCEEDED(RegisterTypeLib(ptlib,
					T2OLE((LPTSTR)(LPCTSTR)strPathName), T2OLE((LPTSTR)pszHelpDir))))
				bSuccess = TRUE;
		}

		RELEASE(ptlib);
	}
	else
	{
		TRACE1("Warning: Could not load type library from %s\n", (LPCTSTR)strPathName);
	}

	return bSuccess;
}
示例#19
0
void CNetscapeCntrItem::OnActivate()
{
	char * pSource = NULL;
	const char* ptr;
	LPDISPATCH pdisp;
	HRESULT hr;
	int _convert;
	if (m_lpObject->QueryInterface(IID_IDispatch, (void**)&pdisp) == S_OK){
#ifdef XP_WIN32
		LPCOLESTR lpOleStr = T2COLE("SaveAs");
		hr = pdisp->GetIDsOfNames(IID_NULL, (unsigned short **)&lpOleStr, 1, LOCALE_USER_DEFAULT, &m_idSavedAs);
		pdisp->Release();
		if (hr == S_OK)	
			m_bCanSavedByOLE = TRUE;
		else
			m_idSavedAs = DISPID_UNKNOWN;
#else
			m_idSavedAs = DISPID_UNKNOWN;
#endif
	}

	const char* ptr1 = m_csAddress; 
	if (NET_IsLocalFileURL((char*)ptr1)) {
		XP_ConvertUrlToLocalFile(m_csAddress, &pSource);
		m_csDosName = *pSource;  // pick up the drive name.
		m_csDosName += ":";
		m_csDosName += strchr(pSource, '\\');  // pick up the real file name.
		ptr = m_csDosName;	 
		FE_ConvertSpace((char*)ptr);
		XP_FREE(pSource);
	}

	// the object does not support ole automation, try to find out if this is a storagefile, so
	// we can use OLESave().
	if (!m_bCanSavedByOLE) {
#ifdef XP_WIN32		// we will only want to handle saving when the object had storage file.
		int _convert;
		LPCOLESTR lpsz = A2CW(m_csDosName);
		if (StgIsStorageFile(lpsz) == S_OK) 
			m_bCanSavedByOLE = TRUE;
#else                       
		HRESULT sc1 = StgIsStorageFile(m_csDosName);
		if (GetScode(sc1) == S_OK) 
			m_bCanSavedByOLE = TRUE;
#endif
		}

	CGenericView* pView = GetActiveView();
	CFrameGlue *pFrameGlue = pView->GetFrame();
	if(pFrameGlue != NULL)	{
		m_bLocationBarShowing = pFrameGlue->GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR);
	}

	COleClientItem::OnActivate();
}
HRESULT CTCPropBagOnRegKey::_CreateRemoteObject(const _bstr_t& strServer,
  const _bstr_t& strName, IUnknown** ppunkObj, IErrorLog* pErrorLog)
{
  // If DCOM is not installed, take appropriate action
  MCOle32_dll& libOle32 = GetOle32Lib();
  if (!libOle32.Exists_CoCreateInstanceEx())
    return !strServer.length() ?
      CreateLocalObject(strName, ppunkObj, pErrorLog) : E_UNEXPECTED;

  // Read the CLSID of the object saved on the specified subkey
  CLSID clsid;
  CRegKey subkey;
  _bstr_t strObjectID;
  HRESULT hr = GetObjectCLSID(strName, clsid, subkey, strObjectID,
    pErrorLog);
  if (FAILED(hr))
    return hr;

  // Create the object
  USES_CONVERSION;
  _bstr_t bstrServer(strServer);
  COSERVERINFO csi = {0, bstrServer, NULL, 0};
  MULTI_QI mqi = {&IID_IPersistPropertyBag, NULL, 0};
  DWORD dwCtx = CLSCTX_ALL | CLSCTX_REMOTE_SERVER;
  hr = libOle32.CoCreateInstanceEx(clsid, NULL, dwCtx, &csi, 1, &mqi);
  if (FAILED(hr))
  {
    // Use local resources
    MCLibRes res;

    // Format a description string
    _bstr_t strDesc;
    strDesc.Format(IDS_FMT_FAIL_CREATE_CLSID, strObjectID);

    // Log the error
    USES_CONVERSION;
    return LogError("CreateObject", strDesc, hr, T2COLE(strName), pErrorLog);
  }

  // Attach the interface pointer to the smart pointer
  IPersistPropertyBagPtr pppb((IPersistPropertyBag*)mqi.pItf, false);
  
  // Load the object's persistent properties
  CComObjectStack<CTCPropBagOnRegKey> bag;
  bag.Init(subkey, strName, this);
  hr = pppb->Load(&bag, pErrorLog);
  if (FAILED(hr))
    return hr;

  // Detach the IUnknown* and copy to the [out] parameter, don't Release it
  *ppunkObj = pppb.Detach();

  // Indicate success
  return S_OK;
}
示例#21
0
文件: olemisc.cpp 项目: Rupan/winscp
DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPDEVNAMES pDN, LPDEVMODE pDM)
{
	USES_CONVERSION;

	DVTARGETDEVICE* ptd = NULL;
	DWORD dwDevNamesSize, dwDevModeSize, dwPtdSize;

	LPCTSTR lpszDriverName = DEVNAMEPART(pDN, wDriverOffset);
	LPCTSTR lpszDeviceName = DEVNAMEPART(pDN, wDeviceOffset);
	LPCTSTR lpszPortName = DEVNAMEPART(pDN, wOutputOffset);

	LPCOLESTR lpszDriverNameOle = T2COLE(lpszDriverName);
	LPCOLESTR lpszDeviceNameOle = T2COLE(lpszDeviceName);
	LPCOLESTR lpszPortNameOle = T2COLE(lpszPortName);
	int nDriverNameSize = (lpszDriverNameOle == NULL) ? 0 : (ocslen(lpszDriverNameOle)+1)*sizeof(OLECHAR);
	int nDeviceNameSize = (lpszDeviceNameOle == NULL) ? 0 : (ocslen(lpszDeviceNameOle)+1)*sizeof(OLECHAR);
	int nPortNameSize = (lpszPortNameOle == NULL) ? 0 : (ocslen(lpszPortNameOle)+1)*sizeof(OLECHAR);

	LPDEVMODEOLE lpDevModeOle = DEVMODET2OLE(pDM);

	dwDevNamesSize = nDriverNameSize + nDeviceNameSize + nPortNameSize;
	dwDevModeSize = (DWORD)(lpDevModeOle->dmSize + lpDevModeOle->dmDriverExtra);

	dwPtdSize = sizeof(DVTARGETDEVICE) + dwDevNamesSize + dwDevModeSize;

	if ((ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(dwPtdSize)) != NULL)
	{
		// copy in the info
		ptd->tdSize = (UINT)dwPtdSize;

		ptd->tdDriverNameOffset = sizeof(DVTARGETDEVICE);
		ocscpy((LPOLESTR)((BYTE*)ptd + ptd->tdDriverNameOffset), lpszDriverNameOle);
		ptd->tdDeviceNameOffset = (WORD)(ptd->tdDriverNameOffset + nDriverNameSize);
		ocscpy((LPOLESTR)((BYTE*)ptd + ptd->tdDeviceNameOffset), lpszDeviceNameOle);
		ptd->tdPortNameOffset = (WORD)(ptd->tdDeviceNameOffset + nDeviceNameSize);
		ocscpy((LPOLESTR)((BYTE*)ptd + ptd->tdPortNameOffset), lpszPortNameOle);
		ptd->tdExtDevmodeOffset = (WORD)(ptd->tdPortNameOffset + nPortNameSize);
		memcpy((BYTE*)ptd + ptd->tdExtDevmodeOffset, lpDevModeOle,
			sizeof(DEVMODEOLE)+lpDevModeOle->dmDriverExtra);
	}
	return ptd;
}
示例#22
0
HRESULT CCmdTarget::GetTypeInfoOfGuid(LCID lcid, REFGUID guid,
	LPTYPEINFO* ppTypeInfo)
{
	USES_CONVERSION;

	AfxLockGlobals(CRIT_TYPELIBCACHE);

	HRESULT hr = TYPE_E_CANTLOADLIBRARY;
	CTypeLibCache* pTypeLibCache = GetTypeLibCache();
	LPTYPELIB pTypeLib = NULL;

	// If type info is already cached, just return it.
	if (pTypeLibCache->LookupTypeInfo(lcid, guid, ppTypeInfo))
	{
		hr = S_OK;
	}
	else
	{
		// If type library isn't already cached, try to locate it.
		if (!pTypeLibCache->Lookup(lcid, &pTypeLib))
		{
			// First, try getting the subclass to load the type library
			// (normally this goes through LoadRegTypeLib).

			if (FAILED(GetTypeLib(lcid, &pTypeLib)))
			{
				AFX_MANAGE_STATE(m_pModuleState);

				// If that failed, try loading the type library from our own
				// resources.

				TCHAR szPath[_MAX_PATH];
				GetModuleFileName(AfxGetInstanceHandle(), szPath, _MAX_PATH);

				if (FAILED(LoadTypeLib(T2COLE(szPath), &pTypeLib)))
					pTypeLib = NULL;
			}

			pTypeLibCache->Cache(lcid, pTypeLib);
		}

		// If we got a type library, extract the requested type info.
		if (pTypeLib != NULL)
		{
			hr = pTypeLib->GetTypeInfoOfGuid(guid, ppTypeInfo);
			pTypeLib->Release();
			pTypeLibCache->CacheTypeInfo(lcid, guid, *ppTypeInfo);
		}
	}

	AfxUnlockGlobals(CRIT_TYPELIBCACHE);

	return hr;
}
HRESULT CTCPropBagOnRegKey::_ReadVariantFromValue(CRegKey& key,
  const _bstr_t& strPropName, DWORD nType, int cbData, CComVariant& v,
  IErrorLog* pErrorLog)
{
  // Read the value from the registry based on the value type
  switch (nType)
  {
    case REG_DWORD:
    {
      key.GetDWord(strPropName, (DWORD&)V_UI4(&v));
      v.vt = VT_UI4;
      break;
    }

    case REG_SZ:
    {
      _bstr_t strValue;
      key.GetString(strPropName, strValue);
      v = strValue;
      break;
    }

    case REG_BINARY:
    {
      BYTE* pData = new BYTE[cbData];
      key.GetBinary(strPropName, pData, cbData);
      CMemFile file(pData, cbData);
      CArchive ar(&file, CArchive::load, 0);
      ar >> v;
      ar.Close();
      delete [] file.Detach();
      break;
    }

    default:
    {
      // Use local resources
      MCLibRes res;

      // Format a description string
      _bstr_t strDesc;
      strDesc.Format(IDS_FMT_UNSUPPORTED_REGTYPE, nType);

      // Log the error
      USES_CONVERSION;
      return LogError("ReadVariantFromValue", strDesc, E_FAIL,
        T2COLE(strPropName), pErrorLog);
    }
  }

  // Indicate success
  return S_OK;
}
示例#24
0
UINT WriteThreadProc(LPVOID pParam)
{
    USES_CONVERSION;
    LPSTORAGE pStgRoot = NULL;
    g_nIndent = 0;
    VERIFY(::StgCreateDocfile(T2COLE(g_szRootStorageName),
           STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
           0, &pStgRoot) == S_OK);
    ReadDirectory("\\", pStgRoot);
    pStgRoot->Release();
    AfxMessageBox("Write complete");
    return 0;
}
示例#25
0
BOOL AFXAPI AfxResolveShortcut(CWnd* pWnd, LPCTSTR lpszFileIn,
	LPTSTR lpszFileOut, int cchPath)
{
	USES_CONVERSION;
	AFX_COM com;
	IShellLink* psl;
	*lpszFileOut = 0;	// assume failure

	// WINBUG: Win32s versions prior to Win32s 1.3b do not restore the
	//	 stack pointer correctly in SHGetFileInfo.	All it does is return
	//	 failure anyway on Win32s, so here we just avoid calling it.
	if (afxData.bWin31)
		return FALSE;

	SHFILEINFO info;
	if ((SHGetFileInfo(lpszFileIn, 0, &info, sizeof(info),
		SHGFI_ATTRIBUTES) == 0) || !(info.dwAttributes & SFGAO_LINK))
	{
		return FALSE;
	}

	if (FAILED(com.CreateInstance(CLSID_ShellLink, NULL, IID_IShellLink,
		(LPVOID*)&psl)))
	{
		return FALSE;
	}

	IPersistFile *ppf;
	if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf)))
	{
		if (SUCCEEDED(ppf->Load(T2COLE(lpszFileIn), STGM_READ)))
		{
			/* Resolve the link, this may post UI to find the link */
			if (SUCCEEDED(psl->Resolve(pWnd->GetSafeHwnd(),
				SLR_ANY_MATCH)))
			{
//#ifndef _UNICODE
				psl->GetPath(lpszFileOut, cchPath, NULL, 0);
/*#else
				char szTemp[_MAX_PATH];
				psl->GetPath(szTemp, _MAX_PATH, NULL, 0);
				_mbstowcsz(lpszFileOut, szTemp, cchPath);
#endif*/
				return TRUE;
			}
		}
		ppf->Release();
	}
	psl->Release();
	return FALSE;
}
示例#26
0
SCODE _AfxParseDisplayName(LPMONIKER lpmk, LPBC lpbc, LPTSTR lpszRemainder,
	ULONG* cchEaten, LPMONIKER* plpmkOut)
{
	USES_CONVERSION;

	ASSERT(lpmk != NULL);
	ASSERT(AfxIsValidString(lpszRemainder));
	ASSERT(cchEaten != NULL);
	ASSERT(plpmkOut != NULL);

	SCODE sc;
	if (lpbc != NULL)
	{
		// ask moniker to parse the display name itself
		sc = lpmk->ParseDisplayName(lpbc, NULL, T2OLE(lpszRemainder), cchEaten,
			plpmkOut);
	}
	else
	{
		// skip leading delimiters
		int cEaten = 0;
		LPTSTR lpszSrc = lpszRemainder;
		while (*lpszSrc != '\0' && (*lpszSrc == '\\' || *lpszSrc == '/' ||
			*lpszSrc == ':' || *lpszSrc == '!' || *lpszSrc == '['))
		{
			if (_istlead(*lpszSrc))
				++lpszSrc, ++cEaten;
			++lpszSrc;
			++cEaten;
		}

		// parse next token in lpszRemainder
		TCHAR szItemName[_MAX_PATH];
		LPTSTR lpszDest = szItemName;
		while (*lpszSrc != '\0' && *lpszSrc != '\\' && *lpszSrc != '/' &&
			*lpszSrc != ':' && *lpszSrc != '!' && *lpszSrc != '[' &&
			cEaten < _MAX_PATH-1)
		{
			if (_istlead(*lpszSrc))
				*lpszDest++ = *lpszSrc++, ++cEaten;
			*lpszDest++ = *lpszSrc++;
			++cEaten;
		}
		*cchEaten = cEaten;
		sc = CreateItemMoniker(OLESTDDELIMOLE, T2COLE(szItemName), plpmkOut);
	}

	return sc;
}
HRESULT CTCPropBagOnRegKey::_CreateLocalObject(const _bstr_t& strName,
  IUnknown** ppunkObj, IErrorLog* pErrorLog, IUnknown* punkOuter)
{
  // Read the CLSID of the object saved on the specified subkey
  CLSID clsid;
  CRegKey subkey;
  _bstr_t strObjectID;
  HRESULT hr = GetObjectCLSID(strName, clsid, subkey, strObjectID,
    pErrorLog);
  if (FAILED(hr))
    return hr;

  // Create the object
  DWORD dwCtx = CLSCTX_ALL | CLSCTX_REMOTE_SERVER;
  IPersistPropertyBagPtr pppb;
  void** ppv = reinterpret_cast<void**>(&pppb);
  hr = CoCreateInstance(clsid, punkOuter, dwCtx, __uuidof(pppb), ppv);
  if (E_INVALIDARG == hr)
  {
    dwCtx &= ~CLSCTX_REMOTE_SERVER;
    hr = CoCreateInstance(clsid, punkOuter, dwCtx, __uuidof(pppb), ppv);
  }
  if (FAILED(hr))
  {
    // Use local resources
    MCLibRes res;

    // Format a description string
    _bstr_t strDesc;
    strDesc.Format(IDS_FMT_FAIL_CREATE_CLSID, strObjectID);

    // Log the error
    USES_CONVERSION;
    return LogError("CreateObject", strDesc, hr, T2COLE(strName), pErrorLog);
  }

  // Load the object's persistent properties
  CComObjectStack<CTCPropBagOnRegKey> bag;
  bag.Init(subkey, strName, this);
  hr = pppb->Load(&bag, pErrorLog);
  if (FAILED(hr))
    return hr;

  // Detach the IUnknown* and copy to the [out] parameter, don't Release it
  *ppunkObj = pppb.Detach();

  // Indicate success
  return S_OK;
}
示例#28
0
LPMONIKER COleDocument::GetMoniker(OLEGETMONIKER /*nAssign*/)
{
	USES_CONVERSION;

	ASSERT_VALID(this);

	// no moniker for untitled documents
	if (m_strPathName.IsEmpty())
		return NULL;

	// return file moniker based on current path name
	LPMONIKER lpMoniker;
	CreateFileMoniker(T2COLE(m_strPathName), &lpMoniker);
	return lpMoniker;
}
示例#29
0
//读取快捷方式的信息    
BOOL CFileSearch::ReadShortCut(LPTSTR linkName)   
{   
	::CoInitialize(NULL);   
	IShellLink *m_pIShellLink=NULL;   
	IPersistFile *m_pIPersistFile=NULL;   
	HRESULT hr=::CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&m_pIShellLink);   
	if(hr==S_OK)   
	{   
		hr=m_pIShellLink->QueryInterface(IID_IPersistFile,(void **)&m_pIPersistFile); 

		if(hr==S_OK)   
		{   
			USES_CONVERSION;    
			m_pIPersistFile->Load(T2COLE(linkName),STGM_READWRITE);

			char m_strPath[MAX_PATH]={0};   
			m_pIShellLink->GetPath(m_strPath,MAX_PATH,NULL,SLGP_UNCPRIORITY); 

			CString temp = m_strPath;   
			temp.MakeUpper();   

			m_strFind.MakeUpper();

			if (strstr(temp.GetBuffer(),m_strFind.GetBuffer()))  //判断应用程序名
			{
				//AfxMessageBox(temp);

				if(m_pIShellLink) 
					m_pIShellLink->Release(); 

				if(m_pIPersistFile) 
					m_pIPersistFile->Release();  

				::CoUninitialize();   
				return TRUE;   
			}
		}   
	}   
  
	if(m_pIShellLink) 
		m_pIShellLink->Release(); 

	if(m_pIPersistFile) 
		m_pIPersistFile->Release();  

	::CoUninitialize();   
	return FALSE;   
}  
示例#30
0
文件: DbOledb.cpp 项目: okigan/dblib
BOOL COledbCommand::Create(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb->IsOpen());
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
   HRESULT Hr;

   Close();

   // Open the command
   CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
   if( spCreate == NULL ) return FALSE;
   CComPtr<ICommand> spCommand;
   Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
   if( FAILED(Hr) ) return _Error(Hr);
   COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
   m_spText = spCommand;
   _ASSERTE(m_spText);
   USES_CONVERSION;
   Hr = m_spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
   if( FAILED(Hr) ) return _Error(Hr);

   // Prepare the command
   if( (lOptions & DB_OPTION_PREPARE) != 0 ) {
      CComQIPtr<ICommandPrepare> spPrepare = m_spText;
      _ASSERTE(spPrepare);
      if( spPrepare ) {
         Hr = spPrepare->Prepare(0);
         if( FAILED(Hr) ) return _Error(Hr);
      }
   }

   // Create parameter bindings memory area
   long cbAlloc = MAX_PARAMS * sizeof(DBBINDING);
   m_rgBindings = (DBBINDING*) ::CoTaskMemAlloc(cbAlloc);
   if( m_rgBindings == NULL ) return FALSE;
   ::ZeroMemory(m_rgBindings, cbAlloc);

   m_pData = ::CoTaskMemAlloc(MAX_PARAMBUFFER_SIZE);
   _ASSERTE(m_pData);
   if( m_pData == NULL ) return FALSE;
   ::ZeroMemory(m_pData, MAX_PARAMBUFFER_SIZE);

   m_nParams = 0;
   m_dwBindOffset = 0L;

   return TRUE;
}