本文整理汇总了C++中CComSafeArray类的典型用法代码示例。如果您正苦于以下问题:C++ CComSafeArray类的具体用法?C++ CComSafeArray怎么用?C++ CComSafeArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CComSafeArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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;
}
示例4: cbstrTestData
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: GetAssemblyFromAppDomain
HRESULT GetAssemblyFromAppDomain(_AppDomain* appDomain, const wchar_t* assemblyName, _Assembly **assembly)
{
SAFEARRAY* safearray;
CComSafeArray<IUnknown*> assemblies;
CHECKCOM(appDomain->GetAssemblies(&safearray));
assemblies.Attach(safearray);
for (int i = 0, n = assemblies.GetCount(); i < n; i++)
{
CComPtr<_Assembly> a;
a = assemblies[i];
if (a == nullptr)
continue;
CComBSTR assemblyFullName;
CHECKCOM(a->get_FullName(&assemblyFullName));
if (assemblyFullName != nullptr && _wcsnicmp(assemblyFullName, assemblyName, wcslen(assemblyName)) == 0)
{
*assembly = a.Detach();
return S_OK;
}
}
return E_FAIL;
}
示例6:
ITunesEventInterface::ITunesIdSet
ITunesComEventSink::getIdsFromSafeArray( long index,
CComSafeArray<VARIANT>& array )
{
VARIANT elem;
LONG idx2d[2];
idx2d[0] = index;
idx2d[1] = 0;
array.MultiDimGetAt( idx2d, elem );
long sourceId = elem.lVal;
idx2d[1] = 1;
array.MultiDimGetAt( idx2d, elem );
long playlistId = elem.lVal;
idx2d[1] = 2;
array.MultiDimGetAt( idx2d, elem );
long trackId = elem.lVal;
idx2d[1] = 3;
array.MultiDimGetAt( idx2d, elem );
long dbId = elem.lVal;
ITunesEventInterface::ITunesIdSet ids = { sourceId, playlistId, trackId, dbId };
return ids;
}
示例7: UpdateData
void CRegionDlg::OnBnClickedSelect()
{
UpdateData();
ShowWindow(SW_HIDE);
CRect rcCapture;
CComPtr<ITSelectionInfo> pSelInfo;
CComSafeArray<VARIANT, VT_VARIANT> arSafePoints;
int nCount = 0;
LONG hWnd = NULL;
VARIANT points;
if (!theApp.Select(tsSelectionRectangle, pSelInfo))
{
goto Exit;
}
// Capture region
hWnd = pSelInfo->WindowHandle;
pSelInfo->get_Points(&points);
// Ttransform safe arry points
arSafePoints.CopyFrom(points.parray);
nCount = (int)arSafePoints.GetCount();
ATLASSERT(2 == nCount);
if (2 != nCount)
{
goto Exit;
}
rcCapture.SetRect(GET_X_LPARAM(arSafePoints[0].lVal), GET_Y_LPARAM(arSafePoints[0].lVal),
GET_X_LPARAM(arSafePoints[1].lVal), GET_Y_LPARAM(arSafePoints[1].lVal));
// Fill the values
m_strWindowName = theApp.GetWindowText((HWND)(LONG_PTR)hWnd);
m_strWindowHandle.Format(_T("%X"), hWnd);
m_nX = rcCapture.left;
m_nY = rcCapture.top;
m_nWidth = rcCapture.Width();
m_nHeight = rcCapture.Height();
// Capture
DoCapture(hWnd, rcCapture);
UpdateData(FALSE);
Exit:
if (m_nFullHeight > 0)
{
//restore the window
theApp.RestoreWindow(this, m_nFullHeight);
m_nFullHeight = 0;
}
ShowWindow(SW_SHOW);
}
示例8: 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;
}
示例9: displayCCOMBSTRFiles
void displayCCOMBSTRFiles(CComSafeArray<BSTR> fileSet)
{
std::wcout << "Displaying Files Generated from the C++ Interface from COM OBJECT" << std::endl;
for (ULONG i = 0; i < fileSet.GetCount(); i++)
{
std::cout << "Qualified File # " <<i<<" : "<< convertBSTR2stdSTR(fileSet.GetAt(i)) << "\n";
}
}
示例10: convertVector2CCOMSafeArray
CComSafeArray<BSTR> convertVector2CCOMSafeArray(Result x)
{
\
CComSafeArray<BSTR> result;
for (std::string inst : x)
{
result.Add(convertstdSTR2BSTR(inst));
}
return result;
}
示例11: fnNativeLibraryConsumer
// This is an example of an exported function.
NATIVELIBRARYCONSUMER_API int STDAPICALLTYPE fnNativeLibraryConsumer(SAFEARRAY** retval)
{
//sample of returning array from C++
CComSafeArray<VARIANT>* arr = new CComSafeArray<VARIANT>(2);
VARIANT var;
var.vt= VT_INT;
var.intVal = 123;
arr->SetAt(0,var);
arr->SetAt(1,var);
*retval = *(arr->GetSafeArrayPtr());
uses = new CNativeLibrary();
return 42;
}
示例12: 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;
}
示例13:
/**
* Output = Map of topic id and field data - Map to be deleted by caller
*/
std::map<long,CComVariant>* RTDClient::readNewData(){
SAFEARRAY *data_sa;
long topic_count = 0;
HRESULT hr = comObjectScripRTD->RefreshData( &topic_count, &data_sa );
// Pass Address of SAFEARRAY pointer so that we get pointer to 2D safearray
if( FAILED(hr) ){ // Output Data has to be deleted by client
std::cout << "RefreshData COM failure." << " - hr - " << hr << std::endl;
return 0;
}
CComSafeArray<VARIANT> data; // Passing data_sa as Constructor input will copy it, but we need to destroy it after use
data.Attach( data_sa ); // So attach instead and let CComSafeArray handle it
ULONG row_count = data.GetCount(1); // No of Rows = 2nd Dimension Count
if( row_count == 0) return 0 ;
std::map<long,CComVariant> *output = new std::map<long,CComVariant>; // Map: Topicid, Field Data
long index[2];
for( ULONG i=0 ; i<row_count; i++ ){
index[0] = 0; // 0,x - Topic ids. 1,x - Data
index[1] = i;
CComVariant topic_id_var;
data.MultiDimGetAt( index, topic_id_var);
long topic_id = (long)MiscUtil::getLong( topic_id_var );
index[0] = 1;
index[1] = i;
CComVariant topic_data_var;
data.MultiDimGetAt( index, topic_data_var);
if( output->count(topic_id) != 0 && (*output)[topic_id] != topic_data_var ){
std::cout << "Duplicate:"; MiscUtil::printVariant((*output)[topic_id]); std::cout << "-"; MiscUtil::printVariant(topic_data_var);
std::cout << std::endl;
//abort(); // If exists - we can have multiple topic values in same call => use vector
}
(*output)[topic_id] = topic_data_var;
}
return output;
}
示例14: printHistory
void printHistory(CComVariant history) {
if (history.vt == (VT_ARRAY | VT_I2)) {
printf("Ping code history for server: ");
CComSafeArray<SHORT> codes = history.parray;
int codeCount = codes.GetCount();
for (int i = 0; i < codeCount; i++) {
printf("%hd ", codes[i]);
}
printf("\n");
codes.Destroy();
}
else {
printf("Incorrect variant type\n");
}
}
示例15: Transform
STDMETHODIMP CotProjTransform::Transform(LONG count, SAFEARRAY** inX, SAFEARRAY** inY, SAFEARRAY** outX, SAFEARRAY** outY)
{
if(!CheckPointer())
{
return E_FAIL;
}
double *dxs =new double[count];
double *dys =new double[count];
CComSafeArray<double> safeInx;
CComSafeArray<double> safeIny;
safeInx.Attach(*inX);
safeIny.Attach(*inY);
for(long i=0;i<count;i++)
{
dxs[i] =safeInx[i];
dys[i] =safeIny[i];
}
safeInx.Detach();
safeIny.Detach();
//转换
(*m_ppTrans)->Transform(count,dxs,dys);
//将转换结果放到输出数组中
safeInx.Attach(*outX);
safeIny.Attach(*outY);
for(long i=0;i<count;i++)
{
safeInx[i] = dxs[i] ;
safeIny[i] = dys[i] ;
}
safeInx.Detach();
safeIny.Detach();
return S_OK;
}