Ejemplo n.º 1
0
STDMETHODIMP CBDictionary::get_Keys(VARIANT *pKeysArray)
{
	CComSafeArray<VARIANT> bstrArray;
	VARIANT* pVar;
	HRESULT hr;

	m_cs.Enter();

	hr = bstrArray.Create((ULONG)m_posArray.GetCount());
	if(FAILED(hr))
	{
		m_cs.Leave();
		return hr;
	}

	pVar = (VARIANT*)bstrArray.m_psa->pvData;

	for(int i = 0; i < (int)m_posArray.GetCount(); i ++)
	{
		hr = VariantCopy(&pVar[i], (VARIANT*)&m_posArray[i]->m_key);
		if(FAILED(hr))
		{
			m_cs.Leave();
			bstrArray.Destroy();
			return hr;
		}
	}

	m_cs.Leave();

	pKeysArray->vt = VT_ARRAY | VT_VARIANT;
	pKeysArray->parray = bstrArray.Detach();

	return S_OK;
}
Ejemplo n.º 2
0
STDMETHODIMP CXRecords::GetRows(VARIANT key, VARIANT* pVal)
{
	if(!m_pFields)return SetErrorInfo(s_errInit);

	CComSafeArray<VARIANT> bstrArray;
	VARIANT* pVar;
	HRESULT hr;
	int i = 0;
	int pos;
	int count = m_listRecords->GetCount();

	pos = m_pFields->FindField(key);
	if(pos < 0 || pos >= (int)m_pFields->GetCount())
		return DISP_E_BADINDEX;

	hr = bstrArray.Create(count);
	if(FAILED(hr))return hr;

	pVar = (VARIANT*)bstrArray.m_psa->pvData;

	for(i = 0; i < count; i ++)
	{
		hr = VariantCopy(&pVar[i], (VARIANT*)&m_listRecords->GetValue(i)->m_arrayVariant[pos]);
		if(FAILED(hr))
		{
			bstrArray.Destroy();
			return hr;
		}
	}

	pVal->vt = VT_ARRAY | VT_VARIANT;
	pVal->parray = bstrArray.Detach();

	return S_OK;
}
Ejemplo n.º 3
0
STDMETHODIMP CDlrComServer::GetIntArray(SAFEARRAY **ppsaRetVal)
{
    CComSafeArray<INT>      csaData;
    void HUGEP              *pvData = NULL;
    HRESULT hr = S_OK;

    int rgData [] = { 1, 2, 3, 4, 5 };

    hr = csaData.Create(5, 0);
    if (FAILED(hr)) 
        goto Error;

    hr = SafeArrayAccessData((LPSAFEARRAY)csaData, (void HUGEP **)&pvData);
    if (FAILED(hr))
        goto Error;

    memcpy((void*)pvData, rgData, sizeof(rgData));

    hr = SafeArrayUnaccessData((LPSAFEARRAY)csaData);
    if (FAILED(hr))
        goto Error;

    *ppsaRetVal = csaData.Detach();

Error:

    return hr;
}
Ejemplo n.º 4
0
STDMETHODIMP CDlrComServer::GetByteArray(SAFEARRAY **ppsaRetVal)
{
    CComBSTR cbstrTestData(L"GetByteArrayTestData");
    CComSafeArray<BYTE>     csaData;
    void HUGEP              *pvData = NULL;
    DWORD                   cbData;
    HRESULT hr = S_OK;

    // create a stream of bytes encoded as UNICODE text
    cbData = SysStringByteLen(cbstrTestData.m_str);

    hr = csaData.Create(cbData, 0);
    if (FAILED(hr)) 
        goto Error;

    hr = SafeArrayAccessData((LPSAFEARRAY)csaData, (void HUGEP **)&pvData);
    if (FAILED(hr))
        goto Error;

    memcpy((void*)pvData, cbstrTestData.m_str, cbData);

    hr = SafeArrayUnaccessData((LPSAFEARRAY)csaData);
    if (FAILED(hr))
        goto Error;

    if (FAILED(hr))
        goto Error;

    *ppsaRetVal = csaData.Detach();

Error:

    return hr;
}
HRESULT RegisterWithGDEventFramework() {
  CComPtr<IGoogleDesktopRegistrar> registrar;
  HRESULT hr = registrar.CoCreateInstance(L"GoogleDesktop.Registrar");

  if (SUCCEEDED(hr)) {
    CComBSTR our_guid(CONSOLE_PLUGIN_GUID);

    WCHAR icon_path[_MAX_PATH + 1] = {0};
    ATLVERIFY(::GetModuleFileNameW(NULL, icon_path, _MAX_PATH - 2) != 0);
    SafeStrCat(icon_path, L"@0", _MAX_PATH+1);

    CComSafeArray<VARIANT> description;
    ATLVERIFY(SUCCEEDED(description.Create(8)));
    VARIANT* props = reinterpret_cast<VARIANT*>(description.m_psa->pvData);

    for (DWORD i = 0; i < description.GetCount(); ++i) {
      props[i].vt = VT_BSTR;
    }

    props[0].bstrVal = ::SysAllocString(L"Title");
    props[1].bstrVal = ::SysAllocString(L"Console Events");
    props[2].bstrVal = ::SysAllocString(L"Description");
    props[3].bstrVal = ::SysAllocString(L"Outputs events from Google Desktop to the console");
    props[4].bstrVal = ::SysAllocString(L"Icon");
    props[5].bstrVal = ::SysAllocString(icon_path);
    props[6].bstrVal = ::SysAllocString(L"Homepage");
    props[7].bstrVal = ::SysAllocString(L"http://desktop.google.com");

    VARIANT desc;
    desc.vt = VT_ARRAY | VT_VARIANT;
    desc.parray = description;

    hr = registrar->StartComponentRegistration(our_guid, desc);

    if (SUCCEEDED(hr)) {
      CComPtr<IUnknown> unknown;
      hr = registrar->GetRegistrationInterface(CComBSTR(L"GoogleDesktop.EventRegistration"),
                                               &unknown);
      ATLASSERT(SUCCEEDED(hr));

      CComQIPtr<IGoogleDesktopRegisterEventPlugin> event_registration(unknown);
      if (event_registration != NULL) {
        long cookie = 0;
        hr = event_registration->RegisterPlugin(our_guid, &cookie);
        if (SUCCEEDED(hr)) {
          hr = registrar->FinishComponentRegistration();

          if (SUCCEEDED(hr)) {
            hr = StoreRegistrationCookie(cookie);
          }
        }
      }
    }
  }

  return hr;
}
Ejemplo n.º 6
0
STDMETHODIMP CDlrComServer::GetObjArray(SAFEARRAY **ppsaRetVal)
{
    CComSafeArray<LPUNKNOWN>      csaData;
    void HUGEP              *pvData = NULL;
    IUnknown*                     punkThis = NULL;
    IUnknown*                     punkOther = NULL;
    void* rgData[] = { 0, 0 };
    HRESULT hr = S_OK;

    hr = csaData.Create(2, 0);
    if (FAILED(hr)) 
        goto Error;

    hr = SafeArrayAccessData((LPSAFEARRAY)csaData, (void HUGEP **)&pvData);
    if (FAILED(hr))
        goto Error;

    hr = this->QueryInterface(IID_IUnknown, (void**)&punkThis);
    if (FAILED(hr))
        goto Error;

    hr = CoCreateInstance(CLSID_DlrComServer, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&punkOther);
    if (FAILED(hr))
        goto Error;

    rgData[0] = punkThis;
    rgData[1] = punkOther;

    memcpy((void*)pvData, rgData, sizeof(rgData));

    hr = SafeArrayUnaccessData((LPSAFEARRAY)csaData);
    if (FAILED(hr))
        goto Error;

    punkThis = 0;
    punkOther = 0;

    *ppsaRetVal = csaData.Detach();

Error:
    if (punkThis)
        punkThis->Release();

    if (punkOther)
        punkOther->Release();

    return hr;
}
Ejemplo n.º 7
0
STDMETHODIMP CBQueue::get_Items(VARIANT *pItemsArray)
{
	CComSafeArray<VARIANT> bstrArray;
	VARIANT* pVar;
	HRESULT hr;
	POSITION pos;
	int i;

	m_cs.Enter();

	hr = bstrArray.Create((ULONG)m_listItems.GetCount());
	if(FAILED(hr))
	{
		m_cs.Leave();
		return hr;
	}

	pVar = (VARIANT*)bstrArray.m_psa->pvData;

	pos = m_listItems.GetHeadPosition();
	i = 0;

	while(pos)
	{
		hr = VariantCopy(&pVar[i ++], &m_listItems.GetNext(pos));
		if(FAILED(hr))
		{
			m_cs.Leave();
			return hr;
		}
	}

	m_cs.Leave();

	pItemsArray->vt = VT_ARRAY | VT_VARIANT;
	pItemsArray->parray = bstrArray.Detach();

	return S_OK;
}
Ejemplo n.º 8
0
/*
 * Converts the specified (reply) string into a Variant value.
 * If the string contains tab characters ('\t), the string is
 * considered to contain an array of values.
 */
CComVariant CMELCommand::MakeVariant(const CAtlString& strText)
{
	int tabCount = 0;
	int tabPos = 0;
	while (tabPos < strText.GetLength()) {
		tabPos = strText.Find(L'\t', tabPos);
		if (tabPos < 0)
			break;
		++tabCount;
		++tabPos;
	}
	if (!tabCount) {
		return MakeVariantNotArray(strText);
	}
	CComSafeArray<VARIANT> safeArray;
	safeArray.Create(tabCount + 1);
	int curPos = 0;
	int index = 0;
	tabPos = strText.Find(L'\t');
	for (;;) {
		CAtlString strElement;
		if (tabPos > curPos) {
			strElement = strText.Mid(curPos, tabPos - curPos).Trim();
		}
		safeArray[index++] = MakeVariantNotArray(strElement);
		curPos = tabPos + 1;
		if (curPos == strText.GetLength()) {
			safeArray[index] = CComVariant(L"");
			break;
		}
		tabPos = strText.Find(L'\t', curPos);
		if (tabPos < 0) {
			safeArray[index] = MakeVariant(strText.Mid(curPos).Trim());
			break;
		}
	}
	return CComVariant(safeArray);
}