本文整理汇总了C++中CComSafeArray::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ CComSafeArray::Create方法的具体用法?C++ CComSafeArray::Create怎么用?C++ CComSafeArray::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComSafeArray
的用法示例。
在下文中一共展示了CComSafeArray::Create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_Keys
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;
}
示例2: GetRows
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;
}
示例3: GetIntArray
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;
}
示例4: GetByteArray
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;
}
示例5: RegisterWithGDEventFramework
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;
}
示例6: GetObjArray
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;
}
示例7: get_Items
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;
}
示例8: MakeVariant
/*
* 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);
}