Esempio n. 1
1
//***************************************
//* Date            : 5.26.99
//* Last Modified   : 1.20.2000
//* Function name	: DllRegisterServer
//* Description	    : 
//***************************************
//
STDAPI DllRegisterServer(void)
{
	_TCHAR		strCLSID[50];
	OLECHAR		strWideCLSID[50];
	CRegKey		key;
	HRESULT		hr;
	USES_CONVERSION;

	hr = _Module.RegisterServer(TRUE);

	if (SUCCEEDED(hr)) {
		if (::StringFromGUID2(CLSID_CopyPathContextMenu, strWideCLSID, 50) > 0) {
			_tcscpy(strCLSID, OLE2CT(strWideCLSID));
			hr = key.SetValue(HKEY_CLASSES_ROOT, _T("*\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID);
			hr = key.SetValue(HKEY_CLASSES_ROOT, _T("directory\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID);
			hr = key.SetValue(HKEY_CLASSES_ROOT, _T("drive\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID);
		}
	}
	return hr;
}
void CPagePlayers::SectorOrTeamChange(IAGCEvent* pEvent, int iColumn,
  LPCOLESTR pszProperty)
{
  CWaitCursor wait;

  // Get the interesting properties of the event
  CComBSTR bstrName, bstrProperty;
  pEvent->get_SubjectName(&bstrName);
  CComVariant varNewPropertyName;
  pEvent->get_Property(&CComVariant(pszProperty), &varNewPropertyName);
  varNewPropertyName.ChangeType(VT_BSTR);
  bstrProperty = V_BSTR(&varNewPropertyName);

  // Name must not be empty
  _ASSERTE(bstrName.Length());

  // Find the list item with the specified name
  USES_CONVERSION;
  LV_FINDINFO lvfi = {LVFI_STRING, OLE2CT(bstrName)};
  int iIndex = m_listPlayers.FindItem(&lvfi);
  _ASSERTE(iIndex >= 0);

  // Change the sub-item of the list item
  m_listPlayers.SetItemText(iIndex, iColumn,
    bstrProperty.Length() ? OLE2CT(bstrProperty) : TEXT(""));
}
Esempio n. 3
0
HDC WINAPI _AfxOleCreateDC(DVTARGETDEVICE* ptd)
{
	USES_CONVERSION;

	// return screen DC for NULL target device
	if (ptd == NULL)
		return ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);

	LPDEVMODEOLE lpDevMode;
	LPOLESTR lpszDriverName;
	LPOLESTR lpszDeviceName;
	LPOLESTR lpszPortName;

	if (ptd->tdExtDevmodeOffset == 0)
		lpDevMode = NULL;
	else
		lpDevMode  = (LPDEVMODEOLE) ((LPSTR)ptd + ptd->tdExtDevmodeOffset);

	lpszDriverName = (LPOLESTR)((BYTE*)ptd + ptd->tdDriverNameOffset);
	lpszDeviceName = (LPOLESTR)((BYTE*)ptd + ptd->tdDeviceNameOffset);
	lpszPortName   = (LPOLESTR)((BYTE*)ptd + ptd->tdPortNameOffset);

	return ::CreateDC(OLE2CT(lpszDriverName), OLE2CT(lpszDeviceName),
		OLE2CT(lpszPortName), DEVMODEOLE2T(lpDevMode));
}
Esempio n. 4
0
void ReadStorage(LPSTORAGE pStg)
// reads one storage -- recursive calls for substorages
{
    USES_CONVERSION;
    LPSTORAGE pSubStg = NULL;
    LPSTREAM pStream = NULL;
    LPENUMSTATSTG pEnum = NULL;
    LPMALLOC pMalloc = NULL; // for freeing statstg
    STATSTG statstg;
    ULONG nLength;
    BYTE buffer[101];

    g_nIndent++;
    ::CoGetMalloc(MEMCTX_TASK, &pMalloc); // assumes AfxOleInit
                                          //  was called
    VERIFY(pStg->EnumElements(0, NULL, 0, &pEnum) == S_OK);
    while (pEnum->Next(1, &statstg, NULL) == S_OK) {
      if (statstg.type == STGTY_STORAGE) {
        VERIFY(pStg->OpenStorage(statstg.pwcsName, NULL,
               STGM_READ | STGM_SHARE_EXCLUSIVE,
               NULL, 0, &pSubStg) == S_OK);
        ASSERT(pSubStg != NULL);
        TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4,
              g_szBlanks, OLE2CT(statstg.pwcsName));
        ReadStorage(pSubStg);
        pSubStg->Release();
      }
      else if (statstg.type == STGTY_STREAM) {
        VERIFY(pStg->OpenStream(statstg.pwcsName, NULL,
               STGM_READ | STGM_SHARE_EXCLUSIVE,
               0, &pStream) == S_OK);
        ASSERT(pStream != NULL);
        TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4,
               g_szBlanks, OLE2CT(statstg.pwcsName));
        pStream->Read(buffer, 100, &nLength);
        buffer[nLength] = '\0';
        TRACE("%s\n", buffer);
        pStream->Release();
      }
      else {
        ASSERT(FALSE);  // LockBytes?
      }
      pMalloc->Free(statstg.pwcsName); // avoids memory leaks
    }
    pMalloc->Release();
    pEnum->Release();
    g_nIndent--;
}
Esempio n. 5
0
void EnumEmbeds(IHTMLDocument2 *pIHTMLDocument2)
{
	if(!pIHTMLDocument2) return;

	HRESULT hr;
	USES_CONVERSION;

	CComPtr< IHTMLElementCollection > spEmbedCollection;
	hr = pIHTMLDocument2->get_embeds(&spEmbedCollection);	//取得Embed的集合
	if (FAILED(hr))
	{
		cout << _T("错误: 获取Embed集合IHTMLElementCollection!") << endl;
		return;
	}

	long nEmbedCount = 0;				//取得Embed个数
	hr = spEmbedCollection->get_length(&nEmbedCount);
	if (FAILED(hr))
	{
		cout << _T("错误: 获取Embed集合IHTMLElementCollection的长度!") << endl;
	}

	cout << "Embed对象共: " << nEmbedCount << endl;

	CComBSTR bstrPluginsPage, bstrSrc;
	IDispatch *pDisp = NULL;
	CComQIPtr< IHTMLEmbedElement > spEmbedElement;
	for(long i = 0; i < nEmbedCount; i++)
	{
		hr = spEmbedCollection->item(CComVariant(i), CComVariant(), &pDisp);
		if (FAILED(hr) || !pDisp) continue;

		spEmbedElement = pDisp;
		pDisp->Release();
		
		spEmbedElement->get_pluginspage(&bstrPluginsPage);
		spEmbedElement->get_src(&bstrSrc);
		cout << i + 1
			<< ": pluginspage = " << (bstrPluginsPage ? OLE2CT(bstrPluginsPage) : _T(""))
			<< ", src = " << (bstrSrc ? OLE2CT(bstrSrc) : _T("")) 
			<< endl;
	}
	if (pDisp) 
	{
		pDisp->Release();
		pDisp = NULL;
	}
}
Esempio n. 6
0
void CPigEngine::RemoveInvokeCommands(CPigBehaviorScriptType* pType)
{
  // Get the collection of invoke commands for the object
  ITCStringsPtr spInvokeCommands;
  _SVERIFYE(pType->get_InvokeCommands(&spInvokeCommands));
  assert(NULL != spInvokeCommands);

  // Iterate through each one and erase it from the map
  long cInvokeCommands = 0;
  _SVERIFYE(spInvokeCommands->get_Count(&cInvokeCommands));
  XLock lock(this);
  for (_variant_t i(0L); V_I4(&i) < cInvokeCommands; ++V_I4(&i))
  {
    CComBSTR bstrCommand;
    _SVERIFYE(spInvokeCommands->get_Item(&i, &bstrCommand));
    USES_CONVERSION;
    tstring strCommand(OLE2CT(bstrCommand));
    XBehaviorMapIt it = m_mapBehaviors.find(strCommand);
    if (m_mapBehaviors.end() != it)
    {
      it->second->Release();
      m_mapBehaviors.erase(it);
    }
  }
}
Esempio n. 7
0
/**
 *\fn           std::string CLSIDToProgID(const char *clsid)
 *\brief        将CLSID转成类名,CLSID例:{2D7E0F8F-3215-11D0-BF28-0000E8D0D146}
 *\param[in]    const char * clsid 
 *\return       std::string 类名
 */
std::string CAddinProcess::CLSIDToProgID(const char *clsid)
{
    if (NULL == clsid) return "";

    USES_CONVERSION;
    CLSID clsid_data = {0};
    OLECHAR clsid_wstr[100] = {0};
    LPOLESTR prog_id = NULL;

    wcscpy(clsid_wstr, CT2OLE(clsid));

    HRESULT hr = CLSIDFromString(clsid_wstr, &clsid_data);

    if (FAILED(hr)) return "";

    hr = ProgIDFromCLSID(clsid_data, &prog_id);

    if (FAILED(hr)) return "";

    LPCTSTR lpstr =  OLE2CT(prog_id);

    std::string out(lpstr);

    IMalloc * pMalloc = NULL;

    hr = ::CoGetMalloc(1, &pMalloc);   // 取得 IMalloc

    if (SUCCEEDED(hr))
    {
        pMalloc->Free(prog_id);        // 释放ProgID内存
        pMalloc->Release();            // 释放IMalloc
    }

    return out;
}
Esempio n. 8
0
STDMETHODIMP TCUtilImpl::CreateObject(BSTR bstrProgID, BSTR bstrComputer,
  IUnknown** ppUnk)
{
  // Initialize the [out] parameter
  CLEAROUT(ppUnk, (IUnknown*)NULL);

  // Convert the specified ProgID to a CLSID
  CLSID clsid;
  if (!BSTRLen(bstrProgID))
    return E_INVALIDARG;
  RETURN_FAILED(CLSIDFromProgID(bstrProgID, &clsid));

  // Initialize the COSERVERINFO and MULTI_QI structures
  COSERVERINFO csi   = {0, bstrComputer, NULL, 0};
  MULTI_QI     mqi[] =
  {
    {&IID_IUnknown                 , NULL, S_OK},
    {&IID_IDispatch                , NULL, S_OK},
    {&IID_IConnectionPointContainer, NULL, S_OK},
  };
  const static ULONG cMQI = sizeofArray(mqi);

  // Determine if the specified computer name is definitely local
  bool bLocalForSure = true;
  if (BSTRLen(bstrComputer))
  {
    TCHAR szLocal[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD cchLocal = sizeofArray(szLocal);
    GetComputerName(szLocal, &cchLocal);
    USES_CONVERSION;
    bLocalForSure = !_tcsicmp(szLocal, OLE2CT(bstrComputer));
  }
  DWORD dwClsCtx = bLocalForSure ? CLSCTX_SERVER : CLSCTX_REMOTE_SERVER;

  // Attempt to create the instance
  HRESULT hr = CoCreateInstanceEx(clsid, NULL, dwClsCtx, &csi, cMQI, mqi);
  if (FAILED(hr))
  {
    _TRACE_BEGIN
      _TRACE_PART1("TCCreateObject failed: hr=0x%08X", hr);
      _TRACE_PART1(", dwClsCtx=%hs", (CLSCTX_SERVER == dwClsCtx) ?
        "CLSCTX_SERVER" : "CLSCTX_REMOTE_SERVER");
      _TRACE_PART1(", ProgID=\"%ls\"", bstrProgID);
      _TRACE_PART1(", Computer= \"%ls\"\n", bstrComputer ?
        bstrComputer : L"");
    _TRACE_END
    return hr;
  }

  // Copy the IUnknown interface pointer to the [out] parameter
  *ppUnk = mqi[0].pItf;

  // Release each interface not being returned
  for (ULONG i = 1; i < cMQI; ++i)
    if (mqi[i].pItf)
      mqi[i].pItf->Release();

  // Return the result of the QI for IUnknown
  return mqi[0].hr;
}
Esempio n. 9
0
void CWordPadApp::UpdateRegistry()
{
	USES_CONVERSION;
	LPOLESTR lpszClassID = NULL;
	CDocTemplate* pDocTemplate = &DocTemplate;

	// get registration info from doc template string
	CString strServerName;
	CString strLocalServerName;
	CString strLocalShortName;

	if (!pDocTemplate->GetDocString(strServerName,
	   CDocTemplate::regFileTypeId) || strServerName.IsEmpty())
	{
		TRACE0("Error: not enough information in DocTemplate to register OLE server.\n");
		return;
	}
	if (!pDocTemplate->GetDocString(strLocalServerName,
	   CDocTemplate::regFileTypeName))
		strLocalServerName = strServerName;     // use non-localized name
	if (!pDocTemplate->GetDocString(strLocalShortName,
		CDocTemplate::fileNewName))
		strLocalShortName = strLocalServerName; // use long name

	ASSERT(strServerName.Find(' ') == -1);  // no spaces allowed

	::StringFromCLSID(clsid, &lpszClassID);
	ASSERT (lpszClassID != NULL);

	// get path name to server
	TCHAR szLongPathName[_MAX_PATH];
	TCHAR szShortPathName[_MAX_PATH];
	::GetModuleFileName(AfxGetInstanceHandle(), szLongPathName, _MAX_PATH);
	::GetShortPathName(szLongPathName, szShortPathName, _MAX_PATH);

	LPCTSTR rglpszSymbols[NUM_REG_ARGS];
	rglpszSymbols[0] = OLE2CT(lpszClassID);
	rglpszSymbols[1] = strServerName;
	rglpszSymbols[2] = szShortPathName;
	rglpszSymbols[3] = strLocalShortName;
	rglpszSymbols[4] = strLocalServerName;
	rglpszSymbols[5] = m_pszAppName;    // will usually be long, readable name
	rglpszSymbols[6] = NULL;

	if (RegisterHelper((LPCTSTR*)rglpszWordPadRegister, rglpszSymbols, FALSE))
		RegisterHelper((LPCTSTR*)rglpszWordPadOverwrite, rglpszSymbols, TRUE);

//  RegisterExt(_T(".txt"), _T("txtfile"), IDS_TEXT_DOC, rglpszSymbols,
//      (LPCTSTR*)rglpszTxtExtRegister, (LPCTSTR*)rglpszTxtRegister, 3);
	RegisterExt(_T(".rtf"), _T("rtffile"), IDS_RICHTEXT_DOC, rglpszSymbols,
		(LPCTSTR*)rglpszRtfExtRegister, (LPCTSTR*)rglpszRtfRegister, 1);
	RegisterExt(_T(".wri"), _T("wrifile"), IDS_WRITE_DOC, rglpszSymbols,
		(LPCTSTR*)rglpszWriExtRegister, (LPCTSTR*)rglpszWriRegister, 2);
	RegisterExt(_T(".doc"), _T("WordPad.Document.1"), IDS_WINWORD6_DOC, rglpszSymbols,
		(LPCTSTR*)rglpszDocExtRegister, (LPCTSTR*)rglpszDocRegister, 1);

	// free memory for class ID
	ASSERT(lpszClassID != NULL);
	CoTaskMemFree(lpszClassID);
}
Esempio n. 10
0
CComPtr<IHTMLFormElement> GetHTMLForm(IHTMLDocument2* pHTMLDocument2, LPCTSTR lpszName)
{
	if(!pHTMLDocument2) return NULL;

	HRESULT hr;
	USES_CONVERSION;

	CComQIPtr<IHTMLElementCollection> pHTMLForms;
	hr = pHTMLDocument2->get_forms(&pHTMLForms);
	if (FAILED(hr)) return NULL;

	long nCount = 0;
	hr = pHTMLForms->get_length(&nCount);
	if (FAILED(hr)) return NULL;

	IDispatch *pDisp = NULL;
	CComBSTR bstrName;
	CString strName;

	for(long i = 0; i < nCount; i++)
	{
		
		hr = pHTMLForms->item(CComVariant(i), CComVariant(), &pDisp);
		if (FAILED(hr)) continue;

		CComQIPtr<IHTMLFormElement> pHTMLForm = pDisp;
		// here do NOT release the pDisp, or the spFormElement will be released also
		// pDisp->Release();

		pHTMLForm->get_name(&bstrName);
		strName = bstrName ? OLE2CT(bstrName) : _T("");
		if (strName.Compare(lpszName) == 0) return pHTMLForm;
	}
	return NULL;
}
Esempio n. 11
0
CComPtr<IHTMLElement> GetFormInput(IHTMLFormElement* pHTMLForm, LPCTSTR lpszName)
{
	if(!pHTMLForm) return NULL;

	HRESULT hr;
	USES_CONVERSION;

	IDispatch *pDisp = NULL;
	CComBSTR bstrName;
	CString strName;

	long nCount = 0;
	hr = pHTMLForm->get_length(&nCount);
	if (FAILED(hr))	return NULL;

	for(long j = 0; j < nCount; j++)
	{
		hr = pHTMLForm->item(CComVariant(j), CComVariant(), &pDisp);
		if (FAILED(hr)) continue;

		CComQIPtr<IHTMLElement> pFormInput = pDisp;
		// here do NOT release the pDisp, or the spInputElement will be released also
		// pDisp->Release();

		hr = pFormInput->get_id(&bstrName);
		if(FAILED(hr)) continue;
		strName = bstrName ? OLE2CT(bstrName) : _T("");
		if (strName.Compare(lpszName) == 0) return pFormInput;
	}

	return NULL;
}
void CPagePlayers::AddPlayer(IAGCEvent* pEvent)
{
  CWaitCursor wait;
  LPCSTR pszContext = "adding new player to the list";
  HRESULT hr;

  // Get the interesting properties of the event
  CComBSTR bstrName;
  pEvent->get_SubjectName(&bstrName);
  long idPlayer = -1;
  pEvent->get_SubjectID(&idPlayer);

  // Name must not be empty
  _ASSERTE(bstrName.Length());

  // Name must not already be in list
  USES_CONVERSION;
  LV_FINDINFO lvfi = {LVFI_STRING, OLE2CT(bstrName)};
  int iIndex = m_listPlayers.FindItem(&lvfi);
  _ASSERTE(-1 == iIndex);

  // Get the IAdminUser for the specified user
  IAdminUserPtr spUser;
//  if (FAILED(hr = GetSheet()->GetServer()->get_LookupUser(
//    static_cast<AGCUniqueID>(idPlayer), &spUser)))
  if (FAILED(hr = GetSheet()->GetServer()->get_FindUser(bstrName, &spUser)))
  {
    GetSheet()->HandleError(hr, pszContext, true);
    return;
  }

  // Get the ship object of the user
  IAdminShipPtr spShip;
  if (FAILED(hr = spUser->get_Ship(&spShip)))
  {
    GetSheet()->HandleError(hr, pszContext, true);
    return;
  }

  // Add the user to the list
  iIndex = m_listPlayers.GetItemCount();
  m_listPlayers.InsertItem(iIndex, OLE2CT(bstrName));
  m_listPlayers.SetItemText(iIndex, c_iColumnTeam, TEXT(""));
  m_listPlayers.SetItemText(iIndex, c_iColumnSector, TEXT(""));
  m_listPlayers.SetItemData(iIndex, reinterpret_cast<DWORD>(spShip.Detach()));
}
STDMETHODIMP CSimplePointWorkspaceFactory::IsWorkspace(BSTR wksString, VARIANT_BOOL *isWks)
{
	USES_CONVERSION;
	*isWks = VARIANT_FALSE;

	if (!IsDirectory(wksString))
		return S_FALSE;

	// verify that a .spt file exists
	CComBSTR sFilter = "*";
	sFilter.Append(g_sExt);

	if (!FileTypeExists(OLE2CT(wksString), OLE2CT(sFilter)))
		return S_FALSE;
	
	*isWks = VARIANT_TRUE;
	return S_OK;
}
Esempio n. 14
0
STDMETHODIMP GvField::setValueFromString( /* [in] */ BSTR value)
{
	const char *vs;
	USES_CONVERSION;
	vs = OLE2CT(value);
	int ret=set(vs);
	COM_EXTERN_TOUCH();
	return ((ret>0) ?  S_OK : S_FALSE);
}
Esempio n. 15
0
BOOL AFXAPI AfxOleUnregisterClass(REFCLSID clsid, LPCTSTR pszProgID)
{
	USES_CONVERSION;

	// Format class ID as a string
	OLECHAR szClassID[GUID_CCH];
	int cchGuid = ::StringFromGUID2(clsid, szClassID, GUID_CCH);
	LPCTSTR lpszClassID = OLE2CT(szClassID);

	ASSERT(cchGuid == GUID_CCH);    // Did StringFromGUID2 work?
	if (cchGuid != GUID_CCH)
		return FALSE;

	TCHAR szKey[_MAX_PATH];
	long error;
	BOOL bRetCode = TRUE;

	// check to see if a 16-bit InprocServer key is found when unregistering
	// 32-bit (or vice versa).
	wsprintf(szKey, _T("CLSID\\%s\\%s"), lpszClassID, INPROCSERVER_2);
	HKEY hkey;
	BOOL bSurgical = RegOpenKey(HKEY_CLASSES_ROOT, szKey, &hkey) ==
		ERROR_SUCCESS;

	if (bSurgical)
	{
		// Only remove the keys specific to this version of the control,
		// leaving things in tact for the other version.
		wsprintf(szKey, _T("CLSID\\%s\\%s"), lpszClassID, INPROCSERVER);
		error = RegDeleteKey(HKEY_CLASSES_ROOT, szKey);
		bRetCode = bRetCode && _AfxRegDeleteKeySucceeded(error);

		wsprintf(szKey, _T("CLSID\\%s\\%s"), lpszClassID, TOOLBOXBITMAP);
		error = RegDeleteKey(HKEY_CLASSES_ROOT, szKey);
		bRetCode = bRetCode && _AfxRegDeleteKeySucceeded(error);
	}
	else
	{
		// No other versions of this control were detected,
		// so go ahead and remove the control completely.
		wsprintf(szKey, _T("CLSID\\%s"), lpszClassID);
		error = _AfxRecursiveRegDeleteKey(HKEY_CLASSES_ROOT, szKey);
		bRetCode = bRetCode && _AfxRegDeleteKeySucceeded(error);

		if (pszProgID != NULL)
		{
			error = _AfxRecursiveRegDeleteKey(HKEY_CLASSES_ROOT,
				(LPTSTR)pszProgID);
			bRetCode = bRetCode && _AfxRegDeleteKeySucceeded(error);
		}
	}

	return bRetCode;
}
Esempio n. 16
0
CPigBehaviorScriptType* CPigEngine::GetBehaviorType(BSTR bstrType)
{
  // Find a behavior type that goes by the specified name
  XLock lock(this);
  USES_CONVERSION;
  XBehaviorMapIt it = m_mapBehaviors.find(tstring(OLE2CT(bstrType)));
  if (m_mapBehaviors.end() == it)
    return NULL;

  // Return the located behavior type
  return it->second;
}
CString CItemPageAnalyzeBase::_GetCollectionItemValue(CComQIPtr<IHTMLElementCollection>& spChildElements, 
													  INT index, ItemValueType valueType, BOOL bTrim /* = FALSE */)
{
	HRESULT hr = E_FAIL;

	CString strResult;
	CComVariant varIndex(index);
	CComPtr<IDispatch> spDispValue;

	COM_VERIFY(spChildElements->item(varIndex, varIndex, &spDispValue));
	CComQIPtr<IHTMLElement>	spElement(spDispValue);
	if (spElement)
	{
		CComBSTR bstrValue;

		switch (valueType)
		{
		case ivtInnerText:
			COM_VERIFY(spElement->get_innerText(&bstrValue));
			strResult = OLE2CT(bstrValue);
			break;
		case ivtToString:
			COM_VERIFY(spElement->toString(&bstrValue));
			strResult = OLE2CT(bstrValue);
			break;
		default:
			FTLASSERT(FALSE);
			break;
		}
	}
	if (bTrim)
	{
		strResult.Trim();
	}
	return strResult;
}
Esempio n. 18
0
void EnumDocument(IHTMLDocument2 *pIHTMLDocument2, HWND hWnd)
{
	HRESULT hr;
	USES_CONVERSION;

	if(hWnd == NULL) hWnd = GetWindowHandle(pIHTMLDocument2);
	if (hWnd != NULL)
	{
		HWND hParentWnd = ::GetAncestor(hWnd, GA_ROOTOWNER);
		TCHAR lpCaption[MAX_PATH] = {0};
		::GetWindowText(hParentWnd, lpCaption, MAX_PATH);
		cout << _T("============") << hParentWnd << lpCaption << _T("============") << endl;
	}
	if (!pIHTMLDocument2) return;

	CComBSTR bstrTitle, bstrURL, bstrHTML;
	pIHTMLDocument2->get_title(&bstrTitle);	//取得文档标题
	pIHTMLDocument2->get_URL(&bstrURL);

	CComQIPtr <IHTMLElement> spBody;
	hr = pIHTMLDocument2->get_body(&spBody);
	if (FAILED(hr)) return;
	
	CComQIPtr <IHTMLElement> spHTML;
	hr = spBody->get_parentElement(&spHTML);
	if (FAILED(hr)) return;
	spHTML->get_outerHTML(&bstrHTML);
	
	cout << _T("Title: ") << (bstrTitle ? OLE2CT(bstrTitle) : _T("")) << endl;
	cout << _T("URL: ") << (bstrURL ? OLE2CT(bstrURL) : _T("")) << endl;
	// cout << _T("HTML: ") << (bstrHTML ? OLE2CT(bstrHTML) : _T("")) << endl;
	EnumForms(pIHTMLDocument2);
	EnumObjects(pIHTMLDocument2);
	EnumEmbeds(pIHTMLDocument2);
	EnumFrames(pIHTMLDocument2);
}
STDMETHODIMP CTCPropBagOnRegKey::CreateKey(BSTR bstrRegKey,
  VARIANT_BOOL bReadOnly)
{
  // Interpret the first part of the specified registry key string
  DWORD cchEaten;
  HKEY hkeyRoot = RootKeyFromString(bstrRegKey, &cchEaten);
  if (!hkeyRoot)
  {
    ZError("CTCPropBagOnRegKey::CreateKey(): Invalid registry key name specified.");
    return E_INVALIDARG;
  }

  // Increment the string past the root key string
  bstrRegKey += cchEaten;

  // Determine the specified access permission
  REGSAM regsam = bReadOnly ? KEY_READ : KEY_ALL_ACCESS;

  // Attempt to create/open the specified subkey of the specified key
  long lr;
  HKEY hkeyOpen = NULL;
  DWORD dw;
  if (IsWinNT())  // Take advantage of Unicode BSTR's under WinNT
  {
    lr = RegCreateKeyExW(hkeyRoot, bstrRegKey, 0, REG_NONE,
      REG_OPTION_NON_VOLATILE, regsam, NULL, &hkeyOpen, &dw);
  }
  else
  {
    USES_CONVERSION;
    lr = RegCreateKeyEx(hkeyRoot, OLE2CT(bstrRegKey), 0, REG_NONE,
      REG_OPTION_NON_VOLATILE, regsam, NULL, &hkeyOpen, &dw);
  }
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Save the new open registry key
  XLock lock(this);
  ClosePrevious();
  m_key.Attach(hkeyOpen);
  m_bOwnKey = true;

  // Indicate success
  return S_OK;
}
Esempio n. 20
0
//////////////////////////////////////////////////////////////////////
//功能:根据名字查找环境属性
//////////////////////////////////////////////////////////////////////
CAmbientProperty* CDevObjDoc::FindAmbientProperty( LPCOLESTR pszName )
{
	USES_CONVERSION;
	int iProp;
	LPCTSTR pszNameT;

	pszNameT = OLE2CT(pszName);
	for (iProp = 0; iProp < m_apAmbientProperties.GetSize(); iProp++)
	{
		if (m_apAmbientProperties[iProp]->GetName() == pszNameT)
		{
			return m_apAmbientProperties[iProp];
		}
	}

	// We didn't find the property.
	return NULL;
}
void CPagePlayers::RemovePlayer(IAGCEvent* pEvent)
{
  // Get the interesting properties of the event
  CComBSTR bstrName;
  pEvent->get_SubjectName(&bstrName);

  // Name must not be empty
  _ASSERTE(bstrName.Length());

  // Name must already be in list
  USES_CONVERSION;
  LV_FINDINFO lvfi = {LVFI_STRING, OLE2CT(bstrName)};
  int iIndex = m_listPlayers.FindItem(&lvfi);
  _ASSERTE(-1 != iIndex);

  // Remove the item from the list
  m_listPlayers.DeleteItem(iIndex);
}
Esempio n. 22
0
HRESULT LoadTypeLib(HINSTANCE hInstTypeLib, LPCOLESTR lpszIndex, BSTR* pbstrPath, ITypeLib** ppTypeLib)
{
	ATLASSERT(pbstrPath != NULL && ppTypeLib != NULL);
	if (pbstrPath == NULL || ppTypeLib == NULL)
		return E_POINTER;

	*pbstrPath = NULL;
	*ppTypeLib = NULL;

	USES_CONVERSION;
	ATLASSERT(hInstTypeLib != NULL);
	TCHAR szModule[MAX_PATH+10];

	DWORD dwFLen = ::GetModuleFileName(hInstTypeLib, szModule, MAX_PATH);
	if( dwFLen == 0 )
		return HRESULT_FROM_WIN32(::GetLastError());
	else if( dwFLen == MAX_PATH )
		return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);

	// get the extension pointer in case of fail
	LPTSTR lpszExt = NULL;

	lpszExt = ::PathFindExtension(szModule);

	if (lpszIndex != NULL)
		lstrcat(szModule, OLE2CT(lpszIndex));
	LPOLESTR lpszModule = T2OLE(szModule);
	HRESULT hr = ::LoadTypeLib(lpszModule, ppTypeLib);
	if (!SUCCEEDED(hr))
	{
		// typelib not in module, try <module>.tlb instead
		lstrcpy(lpszExt, _T(".tlb"));
		lpszModule = T2OLE(szModule);
		hr = ::LoadTypeLib(lpszModule, ppTypeLib);
	}
	if (SUCCEEDED(hr))
	{
		*pbstrPath = ::SysAllocString(lpszModule);
		if (*pbstrPath == NULL)
			hr = E_OUTOFMEMORY;
	}
	return hr;
}
Esempio n. 23
0
LRESULT CDCSettings::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	USES_CONVERSION;

	AddStrings(m_hWnd, IDC_CAMERA_TYPE, g_rgszCameraTypes);
	AddStrings(m_hWnd, IDC_DEVICE, g_rgszDevices);
	AddStrings(m_hWnd, IDC_SPEED, g_rgszSpeeds);
	AddStrings(m_hWnd, IDC_RESIZE_MODE, g_rgszResizeModes);
	AddStrings(m_hWnd, IDC_STRETCH_MODE, g_rgszStretchModes);

	SendDlgItemMessage(IDC_CAMERA_TYPE, CB_SETCURSEL, 
		(WPARAM)m_fCameraType - 1, 0);

	CComBSTR strDevice = m_strDevice;
	if(!strDevice.Length())
		strDevice = g_szAutomatic;
	SetDlgItemText(IDC_DEVICE, OLE2T(strDevice));
	
	if(m_nSpeed == 0)
		SetDlgItemText(IDC_SPEED, g_szAutomatic);
	else
		SetDlgItemInt(IDC_SPEED, m_nSpeed);

	SendDlgItemMessage(IDC_RESIZE_MODE, CB_SETCURSEL, 
		(WPARAM)m_fResizeMode - 1, 0);
	SendDlgItemMessage(IDC_STRETCH_MODE, CB_SETCURSEL, 
		(WPARAM)m_fStretchMode - 1, 0);

	SetDlgItemInt(IDC_DESIGN_WIDTH, m_cxDesignWidth);
	SetDlgItemInt(IDC_DESIGN_HEIGHT, m_cyDesignHeight);

	TCHAR szBuffer[1024];
	// CComBSTR strModule  = GetModuleFilePath();
	// CComBSTR strVersion = GetFileVersion(OLE2CT(strModule));
	CComBSTR strVersion = VER_FILEVERSION_STR;
	wsprintf(szBuffer, "Image Upload Version %s", OLE2CT(strVersion));
	SetDlgItemText(IDC_VERSION, szBuffer);

	UpdateControls();

	return 1;  // Let the system set the focus
}
Esempio n. 24
0
void EnumConnectionPoint(IDispatch *pDisp, LPCSTR comment)
{
	if (!pDisp) return;
	HRESULT hr = S_OK;

	USES_CONVERSION;
	IConnectionPointContainer *spCPC = NULL;
	IConnectionPoint *spCP = NULL;
	IEnumConnectionPoints *ppEnum = NULL;
	IID id;
	LPOLESTR strGUID = 0;
	CComBSTR bstrId = NULL;

	if(comment) cout << comment << _T(" ");
	cout << _T("ConnectionPoint: [");
	hr = pDisp->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&spCPC));
	if (SUCCEEDED(hr) && spCPC)
	{
		hr = spCPC->EnumConnectionPoints(&ppEnum);
		while(SUCCEEDED(ppEnum->Next(1, &spCP, NULL)) && spCP) 
		{
			spCP->GetConnectionInterface(&id);
			// 注意此处StringFromIID的正确用法, 否则会在Debug状态下出错: user breakpoint called from code 0x7c901230
			StringFromIID(id, &strGUID);
			bstrId = strGUID;
			CoTaskMemFree(strGUID);
			cout << (bstrId ? OLE2CT(bstrId) : _T("")) << _T(", ");
		}
	}
	cout << "]" << endl;
	if(spCP) spCP->Release();
	if(ppEnum) ppEnum->Release();
	if(spCPC) spCPC->Release();
/*
	{9bfbbc02-eff1-101a-84ed-00aa00341d07}	IPropertyNotifySink
	{3050f3c4-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents
	{3050f620-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents2
	{00020400-0000-0000-c000-000000000046}	IDispatch
	{1dc9ca50-06ef-11d2-8415-006008c3fbfc}	ITridentEventSink
	{d27cdb6d-ae6d-11cf-96b8-444553540000}	ShockwaveFlashObjects::_IShockwaveFlashEvents
*/
}
Esempio n. 25
0
HRESULT CPigEngine::put_ArtPath(BSTR bstrArtPath)
{
  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified value
  USES_CONVERSION;
  _bstr_t bstrValue(bstrArtPath);
  long lr = key.SetValue(OLE2CT(bstrValue), TEXT("ArtPath"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Set the art path in the Allegiance stuff
  //USES_CONVERSION;
  UTL::SetArtPath(OLE2CA(bstrValue));

  // Indicate success
  return S_OK;
}
Esempio n. 26
0
std::string get_desc_of( const IID &iid)
{
	std::string desc; 
	LPOLESTR iid_str=NULL;
	try
	{
		USES_CONVERSION;
		StringFromCLSID(iid, &iid_str);

		desc.assign(OLE2CT(iid_str));

	}
	catch(...)
	{
	}
	CoTaskMemFree(iid_str);

	HKEY hKey = NULL;

	std::string key(_T("INTERFACE\\") );
	key+=desc;

	if (RegOpenKeyEx(HKEY_CLASSES_ROOT, key.c_str(), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
	{
		TCHAR buf[30];
		DWORD size=30;
		buf[0]=(TCHAR)0;
		if( RegQueryValueEx(hKey, buf, NULL,NULL, (LPBYTE)buf, &size) == ERROR_SUCCESS )
		{
			desc = buf;
#if 0
			desc.insert(0,_T("["));
			desc.insert(0,buf);
			desc.append(_T("]"));
#endif  //0

		}
		RegCloseKey(hKey);
	}
	return desc;
}
Esempio n. 27
0
LPCSTR CComDateTime::Format(DWORD dwFlags, LCID lcid) const
{
	USES_CONVERSION;

	// If null, return empty string
	if (GetStatus() == null)
		return NULL;

	// If invalid, return DateTime resource string
	if (GetStatus() == invalid)
		return NULL;

	CComVariant var;
	// Don't need to trap error. Should not fail due to type mismatch
	COM_VERIFY(VarBstrFromDate(m_dt, lcid, dwFlags, &V_BSTR(&var)));
	var.vt = VT_BSTR;

   strncpy(s_strDate, OLE2CT(V_BSTR(&var)), ELEMENTS_IN(s_strDate));
   s_strDate[ELEMENTS_IN(s_strDate)-1] = '\0';
	return s_strDate;
}
HRESULT CItemPageAnalyzeBase::_InnerParseRowItem(const CString& strTableName, long /*nIndex*/,
												   CComQIPtr<IHTMLElement>& spPriceElementItem, const CString& strSearchItemName)
{
	HRESULT hr = E_FAIL;
	//FTLTRACE(TEXT("ParsePrice:%d\n"), nIndex);

	WowItemInfoPtr spItemInfo(NULL);

	//COM_DETECT_SERVICE_PROVIDER_FROM_LIST(spPriceElementItem);

	if (spPriceElementItem)
	{
		//CFHTMLElementDumper	htmlElementDumper(spPriceElementItem, CFOutputWindowInfoOutput::Instance(), 0);

		CComBSTR bstrId;
		COM_VERIFY(spPriceElementItem->get_id(&bstrId));
		if (bstrId)
		{
			CString strAuctionIdInfo(OLE2CT(bstrId));
			spItemInfo = m_pWowItemManager->GetItemInAHInfo(strAuctionIdInfo);
		}

		if (spItemInfo)
		{
			CComPtr<IDispatch>	spDispItemAll;
			COM_VERIFY(spPriceElementItem->get_all(&spDispItemAll));
			if (spDispItemAll)
			{
				CComQIPtr<IHTMLElementCollection> spChildElements(spDispItemAll);
				_GetRowItemInfo(strTableName, spChildElements, spItemInfo, strSearchItemName);
				//COM_DETECT_INTERFACE_FROM_REGISTER(spDispItemAll);
			}
		}
	}
	return hr;	
}
Esempio n. 29
0
HRESULT CPigEngine::GetInvokeCommands(CPigBehaviorScriptType* pType,
  CPigEngine::XBehaviorMap& mapCommands)
{
  // Get the collection of invoke commands for the new object
  ITCStringsPtr spInvokeCommands;
  _SVERIFYE(pType->get_InvokeCommands(&spInvokeCommands));
  assert(NULL != spInvokeCommands);

  // Iterate through each one and add it to a local map, ignoring duplicates
  long cInvokeCommands = 0;
  _SVERIFYE(spInvokeCommands->get_Count(&cInvokeCommands));
  for (_variant_t i(0L); V_I4(&i) < cInvokeCommands; ++V_I4(&i))
  {
    CComBSTR bstrCommand;
    _SVERIFYE(spInvokeCommands->get_Item(&i, &bstrCommand));
    USES_CONVERSION;
    tstring strCommand(OLE2CT(bstrCommand));

    XBehaviorMapIt it = mapCommands.find(strCommand);
    if (mapCommands.end() == it)
      mapCommands.insert(std::make_pair(strCommand, pType));
  }
  return S_OK;
}
Esempio n. 30
-1
HRESULT CPigEngine::put_AccountServer(BSTR bstrServer)
{
  // Get the number of pigs that exist
  XLock lock(this);
  long cPigs = 0;
  if (m_pPigs)
    RETURN_FAILED(m_pPigs->get_Count(&cPigs));

  // Fail if there are any pigs in existance
  if (cPigs)
    return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST,
      IID_IPigSession, 0, _Module.GetResourceInstance());

  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified value
  USES_CONVERSION;
  long lr = key.SetValue(BSTRLen(bstrServer) ? OLE2CT(bstrServer) : TEXT(""),
    TEXT("AccountServer"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Save the string
  m_bstrAccountServer = bstrServer;

  // Indicate success
  return S_OK;
}